As recommended by RFC 2985, section 5.4.1:
ChallengePassword attribute values generated in accordance with this
version of this document SHOULD use the PrintableString encoding
whenever possible. If internationalization issues make this
impossible, the UTF8String alternative SHOULD be used.
Even though the RFC continues with
PKCS #9-attribute processing systems MUST be able to recognize and
process all string types in DirectoryString values.
there might be older SCEP server implementations that don't accept
UTF8String-encoded passwords. In particular because previous versions of
PKCS#9 defined this attribute's type as a CHOICE between PrintableString
and T61String.
References strongswan/strongswan#1831
/* encode challengePassword attribute */
if (cert->challengePassword.len > 0)
{
+ asn1_t type = asn1_is_printablestring(cert->challengePassword) ?
+ ASN1_PRINTABLESTRING : ASN1_UTF8STRING;
+
challengePassword = asn1_wrap(ASN1_SEQUENCE, "mm",
asn1_build_known_oid(OID_CHALLENGE_PASSWORD),
asn1_wrap(ASN1_SET, "m",
- asn1_simple_object(ASN1_UTF8STRING, cert->challengePassword)
+ asn1_simple_object(type, cert->challengePassword)
));
}