Skip to content

Commit

Permalink
Merge pull request #351 from nsacyber/update-algorithm-oids
Browse files Browse the repository at this point in the history
Certificate Signature OID Update
  • Loading branch information
iadgovuser29 authored Apr 16, 2021
2 parents 760f246 + 46c9640 commit a72554e
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,21 @@ public abstract class Certificate extends ArchivableEntity {
private static final String KEY_USAGE_EO = "ENCIPHER ONLY";
private static final String KEY_USAGE_DO = "DECIPHER ONLY";
private static final String ECDSA_OID = "1.2.840.10045.4.3.2";
private static final String ECDSA_SHA224_OID = "1.2.840.10045.4.1";
private static final String RSA256_OID = "1.2.840.113549.1.1.11";
private static final String RSA384_OID = "1.2.840.113549.1.1.12";
private static final String RSA512_OID = "1.2.840.113549.1.1.13";
private static final String RSA224_OID = "1.2.840.113549.1.1.14";
private static final String RSA512_224_OID = "1.2.840.113549.1.1.15";
private static final String RSA512_256_OID = "1.2.840.113549.1.1.16";
private static final String RSA256_STRING = "SHA256WithRSA";
private static final String RSA384_STRING = "SHA384WithRSA";
private static final String RSA224_STRING = "SHA224WithRSA";
private static final String RSA512_STRING = "SHA512WithRSA";
private static final String RSA512_224_STRING = "SHA512-224WithRSA";
private static final String RSA512_256_STRING = "SHA512-256WithRSA";
private static final String ECDSA_STRING = "SHA256WithECDSA";
private static final String ECDSA_SHA224_STRING = "SHA224WithECDSA";

private static final Logger LOGGER = LogManager.getLogger(Certificate.class);

Expand Down Expand Up @@ -416,9 +425,27 @@ public Certificate(final byte[] certificateBytes) throws IOException {
case RSA256_OID:
this.signatureAlgorithm = RSA256_STRING;
break;
case RSA384_OID:
this.signatureAlgorithm = RSA384_STRING;
break;
case RSA224_OID:
this.signatureAlgorithm = RSA224_STRING;
break;
case RSA512_OID:
this.signatureAlgorithm = RSA512_STRING;
break;
case RSA512_224_OID:
this.signatureAlgorithm = RSA512_224_STRING;
break;
case RSA512_256_OID:
this.signatureAlgorithm = RSA512_256_STRING;
break;
case ECDSA_OID:
this.signatureAlgorithm = ECDSA_STRING;
break;
case ECDSA_SHA224_OID:
this.signatureAlgorithm = ECDSA_SHA224_STRING;
break;
default:
break;
}
Expand Down Expand Up @@ -772,18 +799,17 @@ public String isIssuer(final Certificate issuer) throws IOException {
break;
case ATTRIBUTE_CERTIFICATE:
AttributeCertificate attCert = getAttributeCertificate();
String algorithm = "SHA256withRSA";
try {
Signature sig = Signature.getInstance(algorithm);
Signature sig = Signature.getInstance(this.getSignatureAlgorithm());
sig.initVerify(issuerX509.getPublicKey());
sig.update(attCert.getAcinfo().getEncoded());
if (sig.verify(attCert.getSignatureValue().getBytes())) {
isIssuer = "";
}
} catch (NoSuchAlgorithmException
| InvalidKeyException
| SignatureException e) {
LOGGER.error(e);
| SignatureException sigEx) {
LOGGER.error(sigEx);
}
break;
default:
Expand Down

0 comments on commit a72554e

Please sign in to comment.