예제 #1
0
  @Test
  public void testValidityPeriodChecking() throws ParseException {
    Certificate certificate = new Certificate();
    certificate.setName(new Name("/ndn/site1/ksk-1416425377094/KEY/0123/%FD%00%00%01I%C9%8B"));
    certificate.getMetaInfo().setFreshnessPeriod(3600 * 1000.0);
    certificate.setContent(new Blob(PUBLIC_KEY, false));

    certificate.setSignature(new Sha256WithRsaSignature());
    Sha256WithRsaSignature signatureInfo = (Sha256WithRsaSignature) certificate.getSignature();

    signatureInfo.getKeyLocator().setType(KeyLocatorType.KEYNAME);
    signatureInfo.getKeyLocator().setKeyName(new Name("/ndn/site1/ksk-2516425377094/KEY"));

    double notBefore = fromIsoString("20150819T120000");
    double notAfter = fromIsoString("20150823T120000");
    signatureInfo.getValidityPeriod().setPeriod(notBefore, notAfter);

    signatureInfo.setSignature(new Blob(SIG_VALUE, false));

    assertEquals(false, certificate.isInValidityPeriod(fromIsoString("20150819T115959")));
    assertEquals(true, certificate.isInValidityPeriod(fromIsoString("20150819T120000")));
    assertEquals(true, certificate.isInValidityPeriod(fromIsoString("20150823T120000")));
    assertEquals(false, certificate.isInValidityPeriod(fromIsoString("20150823T120001")));
    assertEquals(false, certificate.isInValidityPeriod(fromIsoString("20150921T130000")));
  }
예제 #2
0
  /**
   * Return a new Signature object based on the signature algorithm of the public key with keyName
   * (derived from certificateName).
   *
   * @param certificateName The certificate name.
   * @param digestAlgorithm Set digestAlgorithm[0] to the signature algorithm's digest algorithm,
   *     e.g. DigestAlgorithm.SHA256.
   * @return A new object of the correct subclass of Signature.
   */
  private Signature makeSignatureByCertificate(
      Name certificateName, DigestAlgorithm[] digestAlgorithm) throws SecurityException {
    Name keyName = IdentityCertificate.certificateNameToPublicKeyName(certificateName);
    PublicKey publicKey = privateKeyStorage_.getPublicKey(keyName);
    KeyType keyType = publicKey.getKeyType();

    if (keyType == KeyType.RSA) {
      Sha256WithRsaSignature signature = new Sha256WithRsaSignature();
      digestAlgorithm[0] = DigestAlgorithm.SHA256;

      signature.getKeyLocator().setType(KeyLocatorType.KEYNAME);
      signature.getKeyLocator().setKeyName(certificateName.getPrefix(-1));

      return signature;
    } else if (keyType == KeyType.ECDSA) {
      Sha256WithEcdsaSignature signature = new Sha256WithEcdsaSignature();
      digestAlgorithm[0] = DigestAlgorithm.SHA256;

      signature.getKeyLocator().setType(KeyLocatorType.KEYNAME);
      signature.getKeyLocator().setKeyName(certificateName.getPrefix(-1));

      return signature;
    } else throw new SecurityException("Key type is not recognized");
  }