/** * This method returns the {@code DigestAlgorithm} for the given signature. * * @param signatureId The identifier of the signature, for which the algorithm is sought. * @return The {@code DigestAlgorithm} for the given signature */ public EncryptionAlgorithm getSignatureEncryptionAlgorithm(final String signatureId) { final String signatureEncryptionAlgorithmName = getValue("/DiagnosticData/Signature[@Id='%s']/BasicSignature/EncryptionAlgoUsedToSignThisToken/text()", signatureId); final EncryptionAlgorithm signatureEncryptionAlgorithm = EncryptionAlgorithm.forName(signatureEncryptionAlgorithmName); return signatureEncryptionAlgorithm; }
/** * This method returns the {@code EncryptionAlgorithm} of the first signature. * * @return The {@code EncryptionAlgorithm} of the first signature */ public EncryptionAlgorithm getSignatureEncryptionAlgorithm() { final String signatureEncryptionAlgorithmName = getValue("/DiagnosticData/Signature[1]/BasicSignature/EncryptionAlgoUsedToSignThisToken/text()"); final EncryptionAlgorithm signatureEncryptionAlgorithm = EncryptionAlgorithm.forName(signatureEncryptionAlgorithmName, null); return signatureEncryptionAlgorithm; }
/** * This method returns the public algorithm extracted from public key infrastructure. (ex: RSA) * * @param publicKey * @return */ public static String getPublicKeyEncryptionAlgo(final Key publicKey) { String publicKeyAlgorithm = "?"; // (List of different public key implementations with instanceOf test removed) publicKeyAlgorithm = publicKey.getAlgorithm(); if (!"?".equals(publicKeyAlgorithm)) { try { publicKeyAlgorithm = EncryptionAlgorithm.forName(publicKeyAlgorithm).getName(); } catch (DSSException e) { LOG.error(e.getMessage()); } } return publicKeyAlgorithm; }
/** * This method sets the private key entry used to create the signature. Note that the certificate chain is reset, the encryption algorithm is set and the signature algorithm * is updated. * * @param privateKeyEntry the private key entry used to sign? */ public void setPrivateKeyEntry(final DSSPrivateKeyEntry privateKeyEntry) { this.privateKeyEntry = privateKeyEntry; // When the private key entry is set the certificate chain is reset certificateChain.clear(); setSigningCertificate(privateKeyEntry.getCertificate()); setCertificateChain(privateKeyEntry.getCertificateChain()); final String encryptionAlgorithmName = this.signingCertificate.getPublicKey().getAlgorithm(); this.encryptionAlgorithm = EncryptionAlgorithm.forName(encryptionAlgorithmName); this.signatureAlgorithm = SignatureAlgorithm.getAlgorithm(this.encryptionAlgorithm, this.digestAlgorithm); }
@Override public boolean isSignedBy(final CertificateToken issuerToken) { if (this.issuerToken != null) { return this.issuerToken.equals(issuerToken); } final TimestampValidation timestampValidation = validateTimestampToken(timeStamp, issuerToken); final TimestampValidity timestampValidity = timestampValidation.getValidity(); signatureInvalidityReason = timestampValidity.name(); signatureValid = timestampValidation.isValid(); if (signatureValid) { this.issuerToken = issuerToken; issuerX500Principal = issuerToken.getSubjectX500Principal(); final String algorithm = issuerToken.getPublicKey().getAlgorithm(); final EncryptionAlgorithm encryptionAlgorithm = EncryptionAlgorithm.forName(algorithm); final AlgorithmIdentifier hashAlgorithm = timeStamp.getTimeStampInfo().getHashAlgorithm(); final DigestAlgorithm digestAlgorithm = DigestAlgorithm.forOID(hashAlgorithm.getAlgorithm()); algorithmUsedToSignToken = SignatureAlgorithm.getAlgorithm(encryptionAlgorithm, digestAlgorithm); } return signatureValid; }