Class: RStyx::Keyring::InfPrivateKey
- Inherits:
-
Object
- Object
- RStyx::Keyring::InfPrivateKey
- Defined in:
- lib/rstyx/keyring.rb
Overview
An Inferno private key.
Instance Attribute Summary collapse
-
#owner ⇒ Object
The owner of the private key.
-
#sk ⇒ Object
The private (secret) key as an OpenSSL::PKey::RSA object.
Class Method Summary collapse
-
.from_s(s) ⇒ Object
Create a new private key, given a private key record string such as might be read from an Inferno keyring file.
Instance Method Summary collapse
-
#getpk ⇒ Object
Get the public key information from the private key, which is basically just n and p.
-
#initialize(sk, owner) ⇒ InfPrivateKey
constructor
Create a new Inferno private key, given the OpenSSL private key and the owner.
-
#to_s ⇒ Object
Return the private key information as a string suitable for writing as a protocol message or in the Inferno keyfile format.
Constructor Details
#initialize(sk, owner) ⇒ InfPrivateKey
Create a new Inferno private key, given the OpenSSL private key and the owner
259 260 261 262 |
# File 'lib/rstyx/keyring.rb', line 259 def initialize(sk, owner) @sk = sk @owner = owner end |
Instance Attribute Details
#owner ⇒ Object
The owner of the private key
253 254 255 |
# File 'lib/rstyx/keyring.rb', line 253 def owner @owner end |
#sk ⇒ Object
The private (secret) key as an OpenSSL::PKey::RSA object
249 250 251 |
# File 'lib/rstyx/keyring.rb', line 249 def sk @sk end |
Class Method Details
.from_s(s) ⇒ Object
Create a new private key, given a private key record string such as might be read from an Inferno keyring file.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/rstyx/keyring.rb', line 268 def self.from_s(s) a = s.split("\n") if a.length < 10 raise InvalidKeyException.new("bad private key syntax") end if a[0] != "rsa" raise InvalidKeyException.new("unknown key algorithm #{a[0]}") end # Mind your p's and q's: libsec's p is OpenSSL's q! OpenSSL follows # PKCS#1 in reversing their roles. We need to reverse p and q, and # dmp1 and dmq1 to use OpenSSL, but here we do everything in pure # Ruby as much as we can. sk = OpenSSL::PKey::RSA.new sk.n = Keyring.s2big(a[2]) sk.e = Keyring.s2big(a[3]) sk.d = Keyring.s2big(a[4]) sk.p = Keyring.s2big(a[5]) sk.q = Keyring.s2big(a[6]) sk.dmp1 = Keyring.s2big(a[7]) sk.dmq1 = Keyring.s2big(a[8]) sk.iqmp = Keyring.s2big(a[9]) return(InfPrivateKey.new(sk, a[1])) end |
Instance Method Details
#getpk ⇒ Object
Get the public key information from the private key, which is basically just n and p
297 298 299 300 301 302 |
# File 'lib/rstyx/keyring.rb', line 297 def getpk pk = OpenSSL::PKey::RSA.new pk.n = @sk.n pk.e = @sk.e return(InfPublicKey.new(pk, @owner)) end |
#to_s ⇒ Object
Return the private key information as a string suitable for writing as a protocol message or in the Inferno keyfile format.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/rstyx/keyring.rb', line 307 def to_s str = <<EOS rsa #{@owner} #{Keyring.big2s(@sk.n.to_i)} #{Keyring.big2s(@sk.e.to_i)} #{Keyring.big2s(@sk.d.to_i)} #{Keyring.big2s(@sk.p.to_i)} #{Keyring.big2s(@sk.q.to_i)} #{Keyring.big2s(@sk.dmp1.to_i)} #{Keyring.big2s(@sk.dmq1.to_i)} #{Keyring.big2s(@sk.iqmp.to_i)} EOS return(str) end |