483b06
From 92f450a4b6eacb7950e5414d40d9949076cb096e Mon Sep 17 00:00:00 2001
483b06
From: Nathaniel McCallum <npmccallum@redhat.com>
483b06
Date: Tue, 20 Jun 2017 10:31:15 -0400
483b06
Subject: [PATCH] ipa-otptoken-import: Make PBKDF2 refer to the pkcs5 namespace
483b06
483b06
For some unknown reason, when I wrote the ipa-otptoken-import script
483b06
I used bad input data which had the PBKDF2 parameters in the wrong
483b06
XML namespace. I have corrected this input data to match RFC 6030.
483b06
483b06
https://pagure.io/freeipa/issue/7035
483b06
483b06
Signed-off-by: Nathaniel McCallum <npmccallum@redhat.com>
483b06
Reviewed-By: Martin Basti <mbasti@redhat.com>
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 ipaserver/install/ipa_otptoken_import.py      | 15 ++++++---------
483b06
 ipatests/test_ipaserver/data/pskc-figure7.xml | 16 ++++++++--------
483b06
 2 files changed, 14 insertions(+), 17 deletions(-)
483b06
483b06
diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py
483b06
index 2580e2cfc97f4960af68a5eae407a7ebe3c7a257..31225e96b55c20bd78e9a8650848a28cf9feef63 100644
483b06
--- a/ipaserver/install/ipa_otptoken_import.py
483b06
+++ b/ipaserver/install/ipa_otptoken_import.py
483b06
@@ -52,6 +52,7 @@ class ValidationError(Exception):
483b06
 
483b06
 def fetchAll(element, xpath, conv=lambda x: x):
483b06
     return [conv(e) for e in element.xpath(xpath, namespaces={
483b06
+        "pkcs5": "http://www.rsasecurity.com/rsalabs/pkcs/schemas/pkcs-5v2-0#",
483b06
         "pskc": "urn:ietf:params:xml:ns:keyprov:pskc",
483b06
         "xenc11": "http://www.w3.org/2009/xmlenc11#",
483b06
         "xenc": "http://www.w3.org/2001/04/xmlenc#",
483b06
@@ -175,18 +176,14 @@ class XMLKeyDerivation(six.with_metaclass(abc.ABCMeta, object)):
483b06
 
483b06
 class PBKDF2KeyDerivation(XMLKeyDerivation):
483b06
     def __init__(self, enckey):
483b06
-        params = fetch(enckey, "./xenc11:DerivedKey/xenc11:KeyDerivationMethod/xenc11:PBKDF2-params")
483b06
+        params = fetch(enckey, "./xenc11:DerivedKey/xenc11:KeyDerivationMethod/pkcs5:PBKDF2-params")
483b06
         if params is None:
483b06
             raise ValueError("XML file is missing PBKDF2 parameters!")
483b06
 
483b06
-        salt = fetch(
483b06
-            params, "./xenc11:Salt/xenc11:Specified/text()", base64.b64decode)
483b06
-        itrs = fetch(
483b06
-            params, "./xenc11:IterationCount/text()", int)
483b06
-        klen = fetch(
483b06
-            params, "./xenc11:KeyLength/text()", int)
483b06
-        hmod = fetch(
483b06
-            params, "./xenc11:PRF/@Algorithm", convertHMACType, hashes.SHA1)
483b06
+        salt = fetch(params, "./Salt/Specified/text()", base64.b64decode)
483b06
+        itrs = fetch(params, "./IterationCount/text()", int)
483b06
+        klen = fetch(params, "./KeyLength/text()", int)
483b06
+        hmod = fetch(params, "./PRF/@Algorithm", convertHMACType, hashes.SHA1)
483b06
483b06
         if salt is None:
483b06
             raise ValueError("XML file is missing PBKDF2 salt!")
483b06
diff --git a/ipatests/test_ipaserver/data/pskc-figure7.xml b/ipatests/test_ipaserver/data/pskc-figure7.xml
483b06
index 1fb04fc319d7572d9d25ff34a0ce3378a939dfc6..808e272a5469a1c9eb4087ed53e0907bb80b39ad 100644
483b06
--- a/ipatests/test_ipaserver/data/pskc-figure7.xml
483b06
+++ b/ipatests/test_ipaserver/data/pskc-figure7.xml
483b06
@@ -8,14 +8,14 @@
483b06
     <xenc11:DerivedKey>
483b06
       
483b06
 	  Algorithm="http://www.rsasecurity.com/rsalabs/pkcs/schemas/pkcs-5v2-0#pbkdf2">
483b06
-        <xenc11:PBKDF2-params>
483b06
-          <xenc11:Salt>
483b06
-            <xenc11:Specified>Ej7/PEpyEpw=</xenc11:Specified>
483b06
-          </xenc11:Salt>
483b06
-          <xenc11:IterationCount>1000</xenc11:IterationCount>
483b06
-          <xenc11:KeyLength>16</xenc11:KeyLength>
483b06
-          <xenc11:PRF/>
483b06
-        </xenc11:PBKDF2-params>
483b06
+        <pkcs5:PBKDF2-params>
483b06
+          <Salt>
483b06
+            <Specified>Ej7/PEpyEpw=</Specified>
483b06
+          </Salt>
483b06
+          <IterationCount>1000</IterationCount>
483b06
+          <KeyLength>16</KeyLength>
483b06
+          <PRF/>
483b06
+        </pkcs5:PBKDF2-params>
483b06
       </xenc11:KeyDerivationMethod>
483b06
       <xenc:ReferenceList>
483b06
         <xenc:DataReference URI="#ED"/>
483b06
--
483b06
2.13.5