All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.henricook.tls.x509.CSRUtils.scala Maven / Gradle / Ivy

The newest version!
package com.henricook.tls.x509

import org.bouncycastle.asn1.ASN1Encodable
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers
import org.bouncycastle.asn1.x509.{Extensions, ExtensionsGenerator}
import org.bouncycastle.pkcs.PKCS10CertificationRequest

import scala.util.Try

object CSRUtils {
  def extensionsOf(csr: PKCS10CertificationRequest): Seq[CertExtension] = {
    Try(
      CertExtension.wrap(
        Extensions.getInstance(
          csr
            .getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)
            .head
            .getAttrValues
            .getObjectAt(0)
        )
      )
    ).getOrElse(Nil)
  }

  def encodeExtensions(extensions: Set[CertExtension]): ASN1Encodable = {
    val extGen = new ExtensionsGenerator()
    extensions.foreach { e ⇒
      extGen.addExtension(e.id, e.critical, e.value)
    }
    extGen.generate()
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy