Skip to content

example of adding othername SAN to a CSR? #18

Answered by kdubb
learningSwif asked this question in Q&A
Discussion options

You must be logged in to vote

You just need to construct an OtherName struct, which is an OID and ASN1 value.

// Construct your "OtherName"
let myOtherName = OtherName("1.3.18.0.2.4.318", ASN1.utf8String("test@example.com"))

// Add it to CSR builder
let csr =
try CertificationRequest.Builder()
  .subject(name: NameBuilder().add("Outfox Signing", forTypeName: "CN").name)
  .alternativeNames(names: .otherName(myOtherName))
  .publicKey(keyPair: Self.keyPair, usage: [.keyEncipherment])
  .extendedKeyUsage(keyPurposes: [kp.clientAuth.oid, kp.serverAuth.oid], isCritical: true)
  .build(signingKey: Self.keyPair.privateKey, digestAlgorithm: .sha256)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kdubb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #16 on September 11, 2021 20:41.