Skip to content

Commit

Permalink
fix(Certificate): Use DN of issuer's subject, not DN of issuer's issuer
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Jul 23, 2020
1 parent caedc6c commit dba2673
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ class Certificate constructor(val certificateHolder: X509CertificateHolder) {
}

val subjectDistinguishedName = buildDistinguishedName(subjectCommonName)
val issuerDistinguishedName = if (issuerCertificate != null)
issuerCertificate.certificateHolder.issuer
else
subjectDistinguishedName
val issuerDistinguishedName =
issuerCertificate?.certificateHolder?.subject ?: subjectDistinguishedName
val subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.encoded)

val builder = X509v3CertificateBuilder(
issuerDistinguishedName,
generateRandomBigInteger(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,25 @@ class CertificateTest {

@Test
fun `Issuer DN should be set to subject of issuer certificate`() {
// Use an intermediate CA as the issuer because its subject and issuer would be
// different. If we use a root/self-signed CA, its subject and issuer would be
// the same, which would make it hard to see why the test passed.
val rootCAKeyPair = generateRSAKeyPair()
val rootCACert = Certificate.issue(
"root",
rootCAKeyPair.public,
rootCAKeyPair.private,
stubValidityEndDate,
isCA = true,
pathLenConstraint = 1
)
val issuerCommonName = "The issuer"
val issuerCertificate = Certificate.issue(
issuerCommonName,
issuerKeyPair.public,
issuerKeyPair.private,
stubValidityEndDate,
rootCACert,
isCA = true
)
val subjectCertificate = Certificate.issue(
Expand Down

0 comments on commit dba2673

Please sign in to comment.