Examples of PrivateKeyEntry


Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

  public BouncyCastleTimeStampServer(final Store store, final StoreAlias alias) {
    super();
    Assert.notNull(store, "store");
    Assert.notNull(alias, "alias");
    PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) store.get(alias);
    if (privateKeyEntry == null) {
      throw new TimeStampException("Private key not found for " + alias);
    }
    PrivateKey privateKey = privateKeyEntry.getValue();
    Certificate[] chain = privateKeyEntry.getChain();
    this.init(privateKey, chain);
  }
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

          break;
        case PRIVATE_KEY:
          PrivateKey privateKey = (PrivateKey) this.keyStore.getKey(name, this.toCharArray(password));
          if (privateKey != null) {
            Certificate[] chain = this.keyStore.getCertificateChain(name);
            entry = new PrivateKeyEntry(alias, privateKey, chain);
          }
          break;
        case PUBLIC_KEY:
          PublicKey publicKey = (PublicKey) this.keyStore.getKey(name, this.toCharArray(password));
          if (publicKey != null) {
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

        }
        break;
      case PRIVATE_KEY:
        Identity identity = this.privateKeyMap.get(alias.getName());
        if (identity != null) {
          entry = new PrivateKeyEntry(alias, identity.getPrivateKey(), identity.getChain());
        }
        break;
      case PUBLIC_KEY:
        PublicKey publicKey = this.publicKeyMap.get(alias.getName());
        if (publicKey != null) {
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

    JCAStore jcaStore = new JCAStore(KeyStoreType.JKS);
    for (Entry<String, Certificate> entry : this.certificateMap.entrySet()) {
      jcaStore.add(new CertificateEntry(new Alias(entry.getKey()), entry.getValue()));
    }
    for (Entry<String, Identity> entry : this.privateKeyMap.entrySet()) {
      jcaStore.add(new PrivateKeyEntry(new Alias(entry.getKey()), entry.getValue().getPrivateKey(), entry.getValue().getChain()));
    }
    for (Entry<String, PublicKey> entry : this.publicKeyMap.entrySet()) {
      jcaStore.add(new PublicKeyEntry(new Alias(entry.getKey()), entry.getValue()));
    }
    for (Entry<String, SecretKey> entry : this.secretKeyMap.entrySet()) {
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

  private byte[] singleSign(final byte[] data, final Alias alias) {
    Assert.notEmpty(data, "data");
    try {
      Store store = this.parameters.getStore();
      PrivateKeyEntry privateEntry = (PrivateKeyEntry) store.get(alias, StoreEntryType.PRIVATE_KEY);
     
      if (privateEntry == null) {
        throw new SignerException("Private key '" + alias.getName() + " not found in store");
      }

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     
      PrivateKey privateKey = privateEntry.getValue();
      Certificate[] chain = privateEntry.getChain();
      X509Certificate certificate = (X509Certificate) chain[0];

      DigestType digestType = this.getDigestTypeFromSignature(certificate.getSigAlgName());
      Calendar calendar = Calendar.getInstance();
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

  private byte[] singleSign(final byte[] data, final Alias alias) {
    Assert.notEmpty(data, "data");
    try {
      Store store = this.parameters.getStore();
      PrivateKeyEntry privateEntry = (PrivateKeyEntry) store.get(alias, StoreEntryType.PRIVATE_KEY);

      if (privateEntry == null) {
        throw new SignerException("Private key '" + alias.getName() + " not found in store");
      }

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

      PrivateKey privateKey = privateEntry.getValue();
      Certificate[] chain = privateEntry.getChain();
      X509Certificate certificate = (X509Certificate) chain[0];

      DigestType digestType = this.getDigestTypeFromSignature(certificate.getSigAlgName());
      Calendar calendar = Calendar.getInstance();
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

  public SignatureParameters(final PrivateKeyHolder privateKeyHolder, final SignatureType signatureType) {
    super();
    Alias alias = new Alias(SignatureParameters.DEFAULT_ALIAS_NAME);
    this.store = new MemoryStore();
    this.aliases = new Alias[] { alias };
    this.store.add(new PrivateKeyEntry(alias, privateKeyHolder.getPrivateKey(), privateKeyHolder.getChain()));
    this.signatureType = signatureType;
  }
View Full Code Here

Examples of br.net.woodstock.rockframework.security.store.PrivateKeyEntry

  private byte[] singleSign(final byte[] data, final Alias alias) {
    Assert.notEmpty(data, "data");
    try {
      Store store = this.parameters.getStore();
      PrivateKeyEntry privateEntry = (PrivateKeyEntry) store.get(alias, StoreEntryType.PRIVATE_KEY);

      if (privateEntry == null) {
        throw new SignerException("Private key '" + alias.getName() + " not found in store");
      }

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

      PrivateKey privateKey = privateEntry.getValue();
      Certificate[] chain = privateEntry.getChain();
      X509Certificate certificate = (X509Certificate) chain[0];

      DigestType digestType = this.getDigestTypeFromSignature(certificate.getSigAlgName());
      Calendar calendar = Calendar.getInstance();
View Full Code Here

Examples of java.security.KeyStore.PrivateKeyEntry

    while (aliases.hasMoreElements()) {
      String alias = aliases.nextElement();

      if (keyStore.isKeyEntry(alias)) {
        Entry entry = keyStore.getEntry(alias, protParam);
        PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) entry;

        {
          X509Certificate[] certificateChain = toX509(privateKeyEntry.getCertificateChain());
          String encoded = CertificateUtils.toPem(certificateChain);
          File out = new File(dest, alias + ".crt");
          Files.write(encoded, out, Charsets.UTF_8);
        }

        {
          PrivateKey key = privateKeyEntry.getPrivateKey();
          String encoded = PrivateKeys.toPem(key);
          File out = new File(dest, alias + ".key");
          Files.write(encoded, out, Charsets.UTF_8);
        }
      }
View Full Code Here

Examples of java.security.KeyStore.PrivateKeyEntry

        PrivateKeyCallback.Request req = privKeyCallback.getRequest();
        PrivateKey privKey = null;
        Certificate[] certs = null;
        if (req == null) {
            // no request type - set default key
            PrivateKeyEntry pke = getDefaultPrivateKeyEntry(
                    kstores, passwords);
            if (pke != null) {
                privKey = pke.getPrivateKey();
                certs = pke.getCertificateChain();
            }
            privKeyCallback.setKey(privKey, certs);
            passwords = null;
            return;
        }

        // find key based on request type
        try {
            if (req instanceof PrivateKeyCallback.AliasRequest) {
                PrivateKeyCallback.AliasRequest aReq =
                        (PrivateKeyCallback.AliasRequest)req;

                String alias = aReq.getAlias();
                PrivateKeyEntry privKeyEntry = null;
                if (alias == null) {
                    // use default key
                    privKeyEntry = getDefaultPrivateKeyEntry(kstores, passwords);
                } else {
                    privKeyEntry = SSLUtils.getPrivateKeyEntryFromTokenAlias(alias);
                }

                if (privKeyEntry != null) {
                    privKey = privKeyEntry.getPrivateKey();
                    certs = privKeyEntry.getCertificateChain();
                }
            } else if (req instanceof PrivateKeyCallback.IssuerSerialNumRequest) {
                PrivateKeyCallback.IssuerSerialNumRequest isReq =
                        (PrivateKeyCallback.IssuerSerialNumRequest)req;
                X500Principal issuer = isReq.getIssuer();
                BigInteger serialNum = isReq.getSerialNum();
                if (issuer != null && serialNum != null) {
                    boolean found = false;
                    for (int i = 0; i < kstores.length && !found; i++) {
                        Enumeration aliases = kstores[i].aliases();
                        while (aliases.hasMoreElements() && !found) {
                            String nextAlias = (String)aliases.nextElement();
                            Key key = kstores[i].getKey(nextAlias, passwords[i].toCharArray());
                            if (key != null && (key instanceof PrivateKey)) {
                                Certificate[] certificates =
                                        kstores[i].getCertificateChain(nextAlias);
                                // check issuer/serial
                                X509Certificate eeCert = (X509Certificate)certificates[0];
                                if (eeCert.getIssuerX500Principal().equals(issuer) &&
                                        eeCert.getSerialNumber().equals(serialNum)) {
                                    privKey = (PrivateKey)key;
                                    certs = certificates;
                                    found = true;
                                }
                            }
                        }
                    }
                }
            } else if (req instanceof PrivateKeyCallback.SubjectKeyIDRequest) {
                PrivateKeyCallback.SubjectKeyIDRequest skReq =
                        (PrivateKeyCallback.SubjectKeyIDRequest)req;
                byte[] subjectKeyID = skReq.getSubjectKeyID();
                if (subjectKeyID != null) {
                    boolean found = false;
                    // In DER, subjectKeyID will be an OCTET STRING of OCTET STRING
                    DerValue derValue1 = new DerValue(
                        DerValue.tag_OctetString, subjectKeyID);
                    DerValue derValue2 = new DerValue(
                        DerValue.tag_OctetString, derValue1.toByteArray());
                    byte[] derSubjectKeyID = derValue2.toByteArray();

                    for (int i = 0; i < kstores.length && !found; i++) {
                        Enumeration aliases = kstores[i].aliases();
                        while (aliases.hasMoreElements() && !found) {
                            String nextAlias = (String)aliases.nextElement();
                            Key key = kstores[i].getKey(nextAlias, passwords[i].toCharArray());
                            if (key != null && (key instanceof PrivateKey)) {
                                Certificate[] certificates =
                                        kstores[i].getCertificateChain(nextAlias);
                                X509Certificate eeCert = (X509Certificate)certificates[0];
                                // Extension: SubjectKeyIdentifier
                                byte[] derSubKeyID = eeCert.getExtensionValue(SUBJECT_KEY_IDENTIFIER_OID);
                                if (derSubKeyID != null &&
                                        Arrays.equals(derSubKeyID, derSubjectKeyID)) {
                                    privKey = (PrivateKey)key;
                                    certs = certificates;
                                    found = true;
                                }
                            }
                        }
                    }
                }
            } else if (req instanceof PrivateKeyCallback.DigestRequest) {
                PrivateKeyCallback.DigestRequest dReq =
                        (PrivateKeyCallback.DigestRequest)req;
                byte[] digest = dReq.getDigest();
                String algorithm = dReq.getAlgorithm();

                PrivateKeyEntry privKeyEntry = null;
                if (digest == null) {
                    // get default key
                    privKeyEntry = getDefaultPrivateKeyEntry(kstores, passwords);
                } else {
                    if (algorithm == null) {
                        algorithm = DEFAULT_DIGEST_ALGORITHM;
                    }
                    MessageDigest md = MessageDigest.getInstance(algorithm);
                    privKeyEntry = getPrivateKeyEntry(kstores, passwords, md, digest);
                }

                if (privKeyEntry != null) {
                    privKey = privKeyEntry.getPrivateKey();
                    certs = privKeyEntry.getCertificateChain();
                }
            } else {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE,
                         "invalid request type: " + req.getClass().getName());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.