2

I'm trying to use the 'userCertificate' attribute to hold a 'der' file. I can happily add my certificate using the ldif:

dn: cn=bob,ou=users,dc=home
changetype: modify
add: userCertificate;binary
userCertificate;binary:< file:///home/bob/cert.der

I see my certificate in base64 encoding when I do an ldapsearch and life seems good. But when I try to use ldapcompare:

ldapcompare -D"cn=admin,dc=home" -W "cn=bob,ou=users,dc=home" "userCertificate;binary:< file:///home/bob/cert.der"

I get the error:

Compare Result: Invalid syntax (21)
Additional info: unable to normalize value for matching
UNDEFINED

I get the same error if I try to compare using the base64 encoding

ldapcompare -D"cn=admin,dc=home" -W "cn=bob,ou=users,dc=home" "userCertificate:: base64encodedStringOfStuff"

Any ideas?

  • Not sure if you already figured this out, but could your DER encoded certificate be corrupted somehow? This is working on my systems fine. The only difference is that I loaded the certificate into the usercertificate attribute as Base64 encoded (it wasn't DER encoded; I use PEM). Can you display the usercertificate value as Base64 encoded using ldapsearch -LLL and compare the Base64 encoded value you use in ldapcompare? – Bora May 14 '18 at 17:07
  • @Bora I spent two weeks trying to make this work and failed. I'd really appreciate it if you wrote down exactly what steps you took. i.e exact command to make certificate, exact command/ldif to load certificate into LDAP and exact command to do the ldapcompare. Thanks. – user3856370 May 14 '18 at 17:50
  • Sure thing. I'm going to write it an answer as it allows me to use better formatting – Bora May 14 '18 at 18:38
2

I just get this error: ldap_modify: Undefined attribute type (17) additional info: usercertificate: requires ;binary transfer.

This error message pretty clearly refers to what's mandated in RFC 4523, section 2.1. You simply always have to append ;binary to the attribute name in all LDAP operations affecting attribute userCertificate.

ldap_msgfree ldap_err2string Compare Result: Invalid syntax (21) Additional info: unable to normalize value for matching UNDEFINED

When using compare operation you have to look at which EQUALITY matching rule is available for the assertion attribute.

In subschema userCertificate is declared with EQUALITY certificateExactMatch based on issuer name and serial (see RFC 4523 section 2.5) which means there's no pure octet string match available for that attribute.

So you need to extract the decimal serial number and the issuer DN (LDAP string representation) from the certificate:

$ openssl x509 -noout -nameopt rfc2253 -serial -issuer -inform der -in ~/certs/michael@stroeder.com.cer 
serial=0F560E
issuer=CN=StartCom Class 1 Primary Intermediate Client CA,OU=Secure Digital Certificate Signing,O=StartCom Ltd.,C=IL

Convert hex serial to decimal which is 1005070 in this example and invoke ldapcompare like this:

ldapcompare "cn=Michael Ströder+mail=michael@stroeder.com,dc=stroeder,dc=de" 'userCertificate;binary:{ serialNumber 1005070, issuer "cn=StartCom Class 1 Primary Intermediate Client CA,ou=Secure Digital Certificate Signing,o=StartCom Ltd.,c=IL"}'
TRUE

Additional notes:

  • Be aware that DNs are complex beasts with escaping of special characters which need special treatment on shell command-line. Therefore I'd use a scripting language for this task to avoid some of the trouble.
  • In opposite to modify operations and attribute retrieving you don't need the ;binary transfer type for compare operation. But with OpenLDAP it won't hurt either. Not sure about other LDAP server implementations.
  • Thanks for your input, but since it's 'pretty clear', that's what I've been doing. It doesn't work. my ldapcompare request does have ;binary in it. I've also tried Bora's ldapcompare with and without ;binary. No matter what I do I get the error: Compare Result: Invalid syntax (21) Additional info: unable to normalize value for matching UNDEFINED – user3856370 Jul 21 '18 at 0:32
  • Sorry, missed your compare issue. Edited my answer. – Michael Ströder Jul 21 '18 at 11:25
  • Thanks for the update. I've looked at the RFCs you linked and it's clear to me that I'm doing it wrong. But the RFCs may as well be written in Chinese. They're completely incomprehensible to me. I'd just like a command line example of how to do an ldapcompare on an X509 certificate. This seems to be way harder than I'd hoped. – user3856370 Jul 21 '18 at 11:53
  • It works. I can't even begin to imagine how you worked that out. – user3856370 Jul 21 '18 at 13:03
  • Well, many years PKI and LDAP...but I also had to use certificateExactMatch in a Internet search to look up the assertion value syntax... – Michael Ströder Jul 21 '18 at 13:33
1

Please note that I had a PEM encoded certificate, not a DER encoded one. You can use openssl to convert/display DER in PEM:

openssl x509 -in /home/bob/cert.der -inform DER

This command will display your certificate in PEM format. Something like this:

-----BEGIN CERTIFICATE-----
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQ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JLQwGXFK3xPkK
mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K
-----END CERTIFICATE-----

I removed the top and the bottom lines just to have the Base64-encoded part. And, I executed the following command to load it into the usercertificate attribute:

$ ldapmodify -x -h my.ldap.server -Dcn=ADMIN_DN -W
Enter LDAP Password:

dn: uid=testuser,ou=users,o=foo.com    
changetype: modify
replace: usercertificate
usercertificate:: MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
 EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
 KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
 MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
 MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
 Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
 Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
 OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
 MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ
 NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe
 h10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMB
 Af8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSY
 JhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQ
 V8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFp
 myPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkK
 mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
 vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K

modifying entry "uid=testuser,ou=users,o=foo.com"

$

Note the leading single space in front of each Base64-encoded line. It's the continuation marker in LDIF. And, when I search using ldapsearch, I see:

$ ldapsearch -LLL -x -h my.ldap.server -Dcn=ADMIN_DN -W -b ou=users,o=foo.com uid=testuser usercertificate
Enter LDAP Password:

dn: uid=testuser,ou=users,o=foo.com  
userCertificate;binary:: MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9
 w0BAQUFADBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3
 cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IEN
 BMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVV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< file: directive against a DER or PEM file (without the CERTIFICATE markers). I'll do more investigation to see what's missing. However, if you reduce the multi-line the Base64-encoded certificate (PEM format) into a single line, then you can do the compare as

$ ldapcompare -x -Dcn=ADMIN_DN -W -h my.ldap.server uid=testuser,ou=users,o=foo.com 'usercertificate::MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCevEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K'
Enter LDAP Password:

TRUE
$

I'll update this if/when I can get it working with the < file: directive.

  • I just get this error: ldap_modify: Undefined attribute type (17) additional info: usercertificate: requires ;binary transfer. It can't be a problem with my certificate because I've also tried the one in your example. – user3856370 May 14 '18 at 21:46
  • Maybe I'll throw away all of my LDAP and start from scratch. – user3856370 May 14 '18 at 21:49
  • Started form scratch. It still doesn't work. I can only get ldapmodify to work if I use userCertificate;binary The ldapsearch command then works, but the ldapcompare command returns: Compare Result: Invalid syntax (21) Additional info: unable to normalize value for matching UNDEFINED – user3856370 May 14 '18 at 22:13
  • and that happens whether or not I add the ;binary. I guess I'm just cursed. – user3856370 May 14 '18 at 22:15
  • I can't really replicate this problem on my system which runs OpenLDAP 2.4.45. I also tried this against a directory powered by IBM Security Directory Server 6.4.0.15. It worked the same. The only thing I can think of is that the ldapcompare client you have is buggy (pure speculation on my part, of course). Can you paste the schema definition of the attribute usercertificate you have in your directory? I want to see if there's any difference. – Bora May 16 '18 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.