From eb827cae0d8e8f2f6f106eb507da6d667aca1bfa Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 8 May 2014 03:36:34 -0400 Subject: PKCS8 public import fix. --- HACKING | 11 +++++++++++ KeyRing.hs | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/HACKING b/HACKING index b61c9f5..37c366c 100644 --- a/HACKING +++ b/HACKING @@ -25,3 +25,14 @@ contributers to the kiki project. * This approach keeps the code base fresh without limiting it's ease of install and utility on existing systems. + + +Note about current dependency status: + +Because cryptohash is already packaged for Wheezy and I want to avoid depending +a newer version of the library, I've backported the following to work with +cryptohash-0.7.5: + + crypto-pubkey-0.2.4 (needed to add conditional compilation) + x509-v1.4.5 (changed only the constraint in the cabal file) + diff --git a/KeyRing.hs b/KeyRing.hs index c7ea5fb..b359dab 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -67,6 +67,7 @@ module KeyRing , UserIDRecord(..) , pkcs8 , RSAPublicKey(..) + , PKCS8_RSAPublicKey(..) , rsaKeyFromPacket , secretToPublic , selectPublicKey @@ -78,6 +79,8 @@ module KeyRing , getBindings , accBindings , isSubkeySignature + , extractPEM + , torhash ) where import System.Environment @@ -101,7 +104,7 @@ import Text.Show.Pretty as PP ( ppShow ) import Data.Binary {- decode, decodeOrFail -} import ControlMaybe ( handleIO_ ) import Data.ASN1.Types ( toASN1, ASN1Object, fromASN1 - , ASN1(Start,End,IntVal,OID,BitString), ASN1ConstructionType(Sequence) ) + , ASN1(Start,End,IntVal,OID,BitString,Null), ASN1ConstructionType(Sequence) ) import Data.ASN1.BitArray ( BitArray(..), toBitArray ) import Data.ASN1.Encoding ( encodeASN1, encodeASN1', decodeASN1, decodeASN1' ) import Data.ASN1.BinaryEncoding ( DER(..) ) @@ -426,7 +429,10 @@ instance ASN1Object RSAPublicKey where : IntVal e : End Sequence : xs - fromASN1 _ = + fromASN1 (Start Sequence:IntVal n:IntVal e:End Sequence:xs) = + Right (RSAKey (MPI n) (MPI e), xs) + + fromASN1 _ = Left "fromASN1: RSAPublicKey: unexpected format" instance ASN1Object PKCS8_RSAPublicKey where @@ -446,6 +452,12 @@ instance ASN1Object PKCS8_RSAPublicKey where fromASN1 (Start Sequence:IntVal modulus:IntVal pubexp:End Sequence:xs) = Right (RSAKey8 (MPI modulus) (MPI pubexp) , xs) + fromASN1 (Start Sequence:Start Sequence:OID [1,2,840,113549,1,1,1]:Null:End Sequence:BitString b:End Sequence:xs) = + case decodeASN1' DER bs of + Right as -> fromASN1 as + Left e -> Left ("fromASN1: RSAPublicKey: "++show e) + where + BitArray _ bs = b fromASN1 (Start Sequence:Start Sequence:OID [1,2,840,113549,1,1,1]:End Sequence:BitString b:End Sequence:xs) = case decodeASN1' DER bs of Right as -> fromASN1 as -- cgit v1.2.3