Skip to content

Commit

Permalink
fix(Certificate): Represent CommonName with DERBMPString
Browse files Browse the repository at this point in the history
For consistency with TS implementation.
  • Loading branch information
gnarea committed Jul 23, 2020
1 parent e47a87e commit caedc6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.relaycorp.relaynet.wrappers.x509

import org.bouncycastle.asn1.DERBMPString
import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x500.X500NameBuilder
import org.bouncycastle.asn1.x500.style.BCStyle
Expand Down Expand Up @@ -95,7 +96,7 @@ class Certificate constructor(val certificateHolder: X509CertificateHolder) {
@Throws(CertificateException::class)
private fun buildDistinguishedName(commonName: String): X500Name {
val builder = X500NameBuilder(BCStyle.INSTANCE)
builder.addRDN(BCStyle.CN, commonName)
builder.addRDN(BCStyle.CN, DERBMPString(commonName))
return builder.build()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tech.relaycorp.relaynet.wrappers.x509

import org.bouncycastle.asn1.ASN1ObjectIdentifier
import org.bouncycastle.asn1.DERBMPString
import org.bouncycastle.asn1.x500.X500NameBuilder
import org.bouncycastle.asn1.x500.style.BCStyle
import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier
Expand Down Expand Up @@ -162,6 +163,7 @@ class CertificateTest {
assertEquals(1, distinguishedNames.size)
assertEquals(false, distinguishedNames[0].isMultiValued)
assertEquals(BCStyle.CN, distinguishedNames[0].first.type)
assertTrue(distinguishedNames[0].first.value is DERBMPString)
assertEquals(commonName, distinguishedNames[0].first.value.toString())
}

Expand Down

0 comments on commit caedc6c

Please sign in to comment.