The Inbox: CryptoCerts-rww.3.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: CryptoCerts-rww.3.mcz

commits-2
A new version of CryptoCerts was added to project The Inbox:
http://source.squeak.org/inbox/CryptoCerts-rww.3.mcz

==================== Summary ====================

Name: CryptoCerts-rww.3
Author: rww
Time: 28 September 2010, 6:55:40.311 am
UUID: e0ff4aa4-bfca-6346-9c3f-4c755c5eb069
Ancestors: CryptoCerts-rww.2

refactored Readers such that DSA and RSA Readers are in CryptoCore

=============== Diff against CryptoCerts-rww.2 ===============

Item was removed:
- Object subclass: #DSAPrivateKeyFileReader
- instanceVariableNames: 'bytes decryptedBytes iv password'
- classVariableNames: ''
- poolDictionaries: ''
- category: 'CryptoCerts-X509-Readers'!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader classSide>>fromFile: (in category 'as yet unclassified') -----
- fromFile: filename
- "(DSAPrivateKeyFileReader fromFile: '/usr/local/ssl/private/dsa.key')"
- "(DSAPrivateKeyFileReader fromFile: '/Users/slosher/Desktop/squeak/certificates/dsa.key')"
-
- | fs data |
- fs := StandardFileStream fileNamed: filename.
- data := fs contentsOfEntireFile.
- ^ self new initializeFromFileContents: data.
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>asASN1Value (in category 'converting') -----
- asASN1Value
-
- self decryptedBytes isNil
- ifTrue: [self decrypt].
- ^ ASN1Stream decodeBytes: self decryptedBytes
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>asPrivateKey (in category 'converting') -----
- asPrivateKey
-
- | asn1 |
- asn1 := self asASN1Value.
- ^ DSAPrivateKey p: (asn1 at: 2) q: (asn1 at: 3) g: (asn1 at: 4) x: (asn1 at: 6).
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>asPublicKey (in category 'converting') -----
- asPublicKey
-
- | asn1 |
- asn1 := self asASN1Value.
- ^ DSAPublicKey p: (asn1 at: 2) q: (asn1 at: 3) g: (asn1 at: 4) y: (asn1 at: 5).
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>bytes (in category 'accessing') -----
- bytes
- "Answer the value of bytes"
-
- ^ bytes!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>bytes: (in category 'accessing') -----
- bytes: anObject
- "Set the value of bytes"
-
- bytes := anObject!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>decrypt (in category 'initialization') -----
- decrypt
-
- | cipher key block encryptedStream decryptedStream |
- self password isNil
- ifTrue: [self password: (FillInTheBlank requestPassword: 'Enter your password')].
- key := OpenSSLKeyDerivationFunction new
- derivedKeyFromPassword: self password
- salt: self iv
- size: 24.
- cipher := (TripleDES key: key) cbc initialVector: iv.
- encryptedStream := self bytes readStream.
- decryptedStream := ReadWriteStream on: (ByteArray new: encryptedStream size).
- [encryptedStream atEnd] whileFalse:
- [block := encryptedStream next: 8.
- cipher decryptBlock: block.
- decryptedStream nextPutAll: block].
- self decryptedBytes: decryptedStream contents.
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>decryptedBytes (in category 'accessing') -----
- decryptedBytes
- "Answer the value of decryptedBytes"
-
- ^ decryptedBytes!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>decryptedBytes: (in category 'accessing') -----
- decryptedBytes: anObject
- "Set the value of decryptedBytes"
-
- decryptedBytes := anObject!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>initializeFromFileContents: (in category 'initialization') -----
- initializeFromFileContents: data
-
- | i j theData |
- i := data indexOfSubCollection: '--BEGIN ' startingAt: 1.
- i = 0 ifTrue: [self bytes: data asByteArray. ^ self].
- i := data indexOfSubCollection: 'KEY--' startingAt: i.
- i := data findAnySubStr: String crlf startingAt: i.
- j := data findAnySubStr: String crlf startingAt: i + 1.
- self processProcType: (data copyFrom: i + 1 to: j).
- i := j.
- j := data findAnySubStr: String crlf startingAt: i + 1.
- self processDEKInfo: (data copyFrom: i + 1 to: j).
- i := j.
- j := data indexOfSubCollection: '--END ' startingAt: i.
- theData := (data copyFrom: i to: j)
- reject: [:c | (c = $-) or: [c isSeparator]].
- theData := (Base64MimeConverter mimeDecodeToBytes: theData readStream) contents.
- self bytes: theData.
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>iv (in category 'accessing') -----
- iv
- "Answer the value of iv"
-
- ^ iv!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>iv: (in category 'accessing') -----
- iv: anObject
- "Set the value of iv"
-
- iv := anObject!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>password (in category 'accessing') -----
- password
- "Answer the value of password"
-
- ^ password!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>password: (in category 'accessing') -----
- password: anObject
- "Set the value of password"
-
- password := anObject!

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>processDEKInfo: (in category 'initialization') -----
- processDEKInfo: data
-
- | stream algorithm |
- stream := data readStream.
- stream upTo: $:.
- algorithm := (stream upTo: $,) withBlanksTrimmed.
- self iv: (Integer readFrom: stream base: 16) asByteArray.
- !

Item was removed:
- ----- Method: DSAPrivateKeyFileReader>>processProcType: (in category 'initialization') -----
- processProcType: data
- !

Item was removed:
- Object subclass: #RSAPrivateKeyFileReader
- instanceVariableNames: 'bytes decryptedBytes iv password'
- classVariableNames: ''
- poolDictionaries: ''
- category: 'CryptoCerts-X509-Readers'!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader classSide>>fromFile: (in category 'instance creation') -----
- fromFile: filename
- "(RSAPrivateKeyFileReader fromFile: '/usr/local/ssl/private/CA.key')"
- "(RSAPrivateKeyFileReader fromFile: '/Users/slosher/Desktop/squeak/certificates/rsa.key')"
-
- | fs data |
- fs := StandardFileStream fileNamed: filename.
- data := fs contentsOfEntireFile.
- ^ self new initializeFromFileContents: data.
- !

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>asASN1Value (in category 'converting') -----
- asASN1Value
-
- self decryptedBytes isNil
- ifTrue: [self decrypt].
- ^ ASN1Stream decodeBytes: self decryptedBytes.
- !

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>asPrivateKey (in category 'converting') -----
- asPrivateKey
-
- | asn1 |
- asn1 := self asASN1Value.
- (asn1 at: 1) > 0
- ifTrue: [^ RSAKey exponent: (asn1 at: 3) modulo: (asn1 at: 1)].
- ^ RSAPrivateKey p: (asn1 at: 5) q: (asn1 at: 6) dP: (asn1 at: 7) dQ: (asn1 at: 8) qInv: (asn1 at: 9)!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>asPublicKey (in category 'converting') -----
- asPublicKey
-
- | asn1 |
- asn1 := self asASN1Value.
- ^ RSAKey exponent: (asn1 at: 3) modulo: (asn1 at: 2)!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>bytes (in category 'accessing') -----
- bytes
- "Answer the value of bytes"
-
- ^ bytes!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>bytes: (in category 'accessing') -----
- bytes: anObject
- "Set the value of bytes"
-
- bytes := anObject!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>decrypt (in category 'initialization') -----
- decrypt
-
- | cipher key block encryptedStream decryptedStream |
- self password isNil
- ifTrue: [self password: (FillInTheBlank requestPassword: 'Enter your password')].
- key := OpenSSLKeyDerivationFunction new
- derivedKeyFromPassword: self password
- salt: self iv
- size: 24.
- cipher := (TripleDES key: key) cbc initialVector: iv.
- encryptedStream := self bytes readStream.
- decryptedStream := ReadWriteStream on: (ByteArray new: encryptedStream size).
- [encryptedStream atEnd] whileFalse:
- [block := encryptedStream next: 8.
- cipher decryptBlock: block.
- decryptedStream nextPutAll: block].
- self decryptedBytes: decryptedStream contents.
- !

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>decryptedBytes (in category 'accessing') -----
- decryptedBytes
- "Answer the value of decryptedBytes"
-
- ^ decryptedBytes!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>decryptedBytes: (in category 'accessing') -----
- decryptedBytes: anObject
- "Set the value of decryptedBytes"
-
- decryptedBytes := anObject!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>initializeFromFileContents: (in category 'initialization') -----
- initializeFromFileContents: data
-
- | i j theData |
- i := data indexOfSubCollection: '--BEGIN ' startingAt: 1.
- i = 0 ifTrue: [self derBytes: data asByteArray. ^ self].
- i := data indexOfSubCollection: 'KEY--' startingAt: i.
- i := data findAnySubStr: String crlf startingAt: i.
- j := data findAnySubStr: String crlf startingAt: i + 1.
- self processProcType: (data copyFrom: i + 1 to: j).
- i := j.
- j := data findAnySubStr: String crlf startingAt: i + 1.
- self processDEKInfo: (data copyFrom: i + 1 to: j).
- i := j.
- j := data indexOfSubCollection: '--END ' startingAt: i.
- theData := (data copyFrom: i to: j)
- reject: [:c | (c = $-) or: [c isSeparator]].
- theData := (Base64MimeConverter mimeDecodeToBytes: theData readStream) contents.
- self bytes: theData.
- !

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>iv (in category 'accessing') -----
- iv
- "Answer the value of iv"
-
- ^ iv!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>iv: (in category 'accessing') -----
- iv: anObject
- "Set the value of iv"
-
- iv := anObject!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>password (in category 'accessing') -----
- password
- "Answer the value of password"
-
- ^ password!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>password: (in category 'accessing') -----
- password: anObject
- "Set the value of password"
-
- password := anObject!

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>processDEKInfo: (in category 'initialization') -----
- processDEKInfo: data
-
- | stream algorithm |
- stream := data readStream.
- stream upTo: $:.
- algorithm := (stream upTo: $,) withBlanksTrimmed.
- self iv: (Integer readFrom: stream base: 16) asByteArray.
- !

Item was removed:
- ----- Method: RSAPrivateKeyFileReader>>processProcType: (in category 'initialization') -----
- processProcType: data
- !

Item was removed:
- Object subclass: #RSAPublicKeyFileReader
- instanceVariableNames: 'bytes'
- classVariableNames: ''
- poolDictionaries: ''
- category: 'CryptoCerts-X509-Readers'!

Item was removed:
- ----- Method: RSAPublicKeyFileReader classSide>>fromFile: (in category 'instance creation') -----
- fromFile: filename
- "(RSAPrivateKeyFileReader fromFile: '/usr/local/ssl/private/CA.key')"
- "(RSAPrivateKeyFileReader fromFile: '/Users/slosher/Desktop/squeak/certificates/rsa.key')"
-
- | fs data |
- fs := StandardFileStream fileNamed: filename.
- data := fs contentsOfEntireFile.
- ^ self new initializeFromFileContents: data.
- !

Item was removed:
- ----- Method: RSAPublicKeyFileReader>>asASN1Value (in category 'converting') -----
- asASN1Value
-
- | asn1 |
- asn1 := ASN1Stream decodeBytes: self bytes.
- ^ ASN1Stream decodeBytes: (asn1 at: 2) bytes!

Item was removed:
- ----- Method: RSAPublicKeyFileReader>>asPublicKey (in category 'converting') -----
- asPublicKey
-
- | asn1 |
- asn1 := self asASN1Value.
- ^ RSAKey exponent: (asn1 at: 2) modulo: (asn1 at: 1)!

Item was removed:
- ----- Method: RSAPublicKeyFileReader>>bytes (in category 'accessing') -----
- bytes
- "Answer the value of bytes"
-
- ^ bytes!

Item was removed:
- ----- Method: RSAPublicKeyFileReader>>bytes: (in category 'accessing') -----
- bytes: anObject
- "Set the value of bytes"
-
- bytes := anObject!

Item was removed:
- ----- Method: RSAPublicKeyFileReader>>initializeFromFileContents: (in category 'initialize-release') -----
- initializeFromFileContents: data
-
- | i j theData |
- i := data indexOfSubCollection: '--BEGIN ' startingAt: 1.
- i = 0 ifTrue: [self derBytes: data asByteArray. ^ self].
- i := data indexOfSubCollection: 'KEY--' startingAt: i.
- i := data findAnySubStr: String crlf startingAt: i.
- j := data findAnySubStr: String crlf startingAt: i + 1.
- " self processProcType: (data copyFrom: i + 1 to: j)."
- i := j.
- j := data findAnySubStr: String crlf startingAt: i + 1.
- " self processDEKInfo: (data copyFrom: i + 1 to: j)."
- i := j.
- j := data indexOfSubCollection: '--END ' startingAt: i.
- theData := (data copyFrom: i to: j)
- reject: [:c | (c = $-) or: [c isSeparator]].
- theData := (Base64MimeConverter mimeDecodeToBytes: theData readStream) contents.
- self bytes: theData.
- !

Item was changed:
  ----- Method: X509SubjectPublicKeyInfo>>asRSAPublicKey (in category 'private') -----
  asRSAPublicKey
 
  | keys |
  keys := self subjectPublicKeyDecoded.
+ ^ (RSAPublicKey exponent: (keys at: 2) asInteger modulo: (keys at: 1) asInteger).
- ^ (RSAKey exponent: (keys at: 2) asInteger modulo: (keys at: 1) asInteger).
  !