sshkey 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/README.md +122 -31
- data/lib/sshkey.rb +11 -4
- data/lib/sshkey/version.rb +1 -1
- data/test/sshkey_test.rb +25 -1
- metadata +3 -2
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
SSHKey
|
2
|
-
======
|
1
|
+
# SSHKey
|
3
2
|
|
4
3
|
Generate private and public SSH keys (RSA and DSA supported) using pure Ruby.
|
5
4
|
|
@@ -9,67 +8,159 @@ Tested on the following Rubies: MRI 1.8.7, 1.9.2, 1.9.3, 2.0.0, REE, JRuby (1.7.
|
|
9
8
|
|
10
9
|
[![Build Status](https://secure.travis-ci.org/bensie/sshkey.png)](http://travis-ci.org/bensie/sshkey)
|
11
10
|
|
12
|
-
Usage
|
13
|
-
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### Generate a new key
|
14
14
|
|
15
15
|
When generating a new keypair the default key type is 2048-bit RSA, but you can supply the `type` (RSA or DSA) and `bits` in the options.
|
16
16
|
You can also (optionally) supply a `comment` or `passphrase`:
|
17
17
|
|
18
|
-
```
|
18
|
+
```ruby
|
19
19
|
k = SSHKey.generate
|
20
20
|
|
21
21
|
k = SSHKey.generate(:type => "DSA", :bits => 1024, :comment => "foo@bar.com", :passphrase => "foobar")
|
22
22
|
```
|
23
23
|
|
24
|
+
### Use your existing key
|
25
|
+
|
24
26
|
Return an SSHKey object from an existing RSA or DSA private key (provided as a string)
|
25
27
|
|
26
|
-
```
|
28
|
+
```ruby
|
27
29
|
k = SSHKey.new(File.read("~/.ssh/id_rsa"), :comment => "foo@bar.com")
|
28
30
|
```
|
29
31
|
|
30
|
-
|
32
|
+
### The SSHKey object
|
31
33
|
|
32
|
-
|
33
|
-
# Returns an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA key object
|
34
|
-
# http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/RSA.html
|
35
|
-
# http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/DSA.html
|
36
|
-
k.key_object
|
37
|
-
# => -----BEGIN RSA PRIVATE KEY-----\nMIIEowI...
|
34
|
+
#### Private and public keys
|
38
35
|
|
39
|
-
|
40
|
-
k.private_key
|
41
|
-
# => "-----BEGIN RSA PRIVATE KEY-----\nMIIEowI..."
|
36
|
+
Fetch the private and public keys as strings. Note that the `public_key` is the RSA or DSA public key, not an SSH public key.
|
42
37
|
|
43
|
-
|
44
|
-
k.
|
45
|
-
# => "-----BEGIN RSA PRIVATE KEY-----\
|
38
|
+
```ruby
|
39
|
+
k.private_key
|
40
|
+
# => "-----BEGIN RSA PRIVATE KEY-----\nMIIEoAIBAAKCAQEAvR7l72CT7UBP6P+02Iut8gKKbKyekz/pQxnckPp1VafuaIwC\nMvYfP4ffVJTcY5IhU9mISNxZf6YDQ0TuD1aOrZYG9wsIgGY0nXhOUZxe/Q5I+V7D\nOI/hSzKF7W0cNCvaJPUSo8+soCLNSQ5mjnV3sRZ6uJwGFN30i1GulqHHKkx3vGxb\niaAL9YG58dPSbPGHFTA/epqUyd1fzCuWHyL9dHW7aw4RroNyEtVdiftAQfaK20I2\nueeDfuEtCPaxQYFQqbz5kKnXQx3fwHRpC7/84xHxsrY576evGxHw4p5EJD37scNN\ncneTG3Ly79/VVSAlrSm6ltutx0+S70scCqK0ewIDAQABAoH/MjwC15LPuDVdBIbn\ngp2XlrEWE8fGV1ainzA/ZkMg55+ztBF8hAzcQAPXTqA76jbmo18k1DWzkDSIqVWl\n5m0XeQRg1T4ZBAIh97H9G7BtispAl/yT3nJZZaAF8wsIctMzHp36VYjUUbTs0nsA\nwtZw9JkEAAVxmBlc26TWuyw9uv4fYXuR+uOsWH8jTTVPvxM9FaCCdK+dOMnswm7Y\nlOAlJj5dANkB2KPwIeE461ThyMo9GHEjpsvciMhKLuBoTSucNkhdgapAmYTSI+/1\nf1cA/KEdCMs9ANr1HFujeS01+N1Xrw/yW6EazaDN1oFHCVORtlB295Eac0Wq6y/P\npf1BAoGBAPIw4HQWsolU3f4FdIvc2POAcSJDRgt++I9Qt/QXq1SJ2dGKIveFiJgo\nZjCfHQFVZ8xl64cLzQ1WagZA1JBbbk9g5RxHDxRv7q+Kn3ogugDo9GUoQvpuuAU6\nXHoR/mLinDorJUnttL3U49xTMfrrut4qkUg+daBVptPtylpio6EDAoGBAMfnYq08\nfd/cPEQ2XPeswgtzXsKNLqA6UXBM7ZauKaFLByjy8peMMF6JPOYlBKQif5k+Egmu\nWIe8oTm8Nn5Ymt32bEd+MkHUC7kFzQeiXnM3u0oKzJMXLAvjSTs296g50YM5zJTC\nl64ACQmQOLZ9tdKorl52ZcmdbBEcZ2uwRvkpAoGAKhs5SrWPgLTSi5FjO9W/mkYg\nZTaQ/PqsOC5ubO+Yh/AXgIiln6cFon6Tlax0HIE+tJibpDT3B3SYplGrIxXiTcao\nzovEIWd8deSB6Xe7HuFhbBzd2DBbqf0FiuuJ8KM5ShuqNfovzDkxDGMic198c5eu\n/oJtbNy3Tm0vGxu/GwUCgYAgmRPXShkAq0pMmUzZups+AMdAFIO47ymelXzc6HOz\ncKevPsbefabZk6mRohG6rkF+fMe2Om8HW3QzFQUR32MJtQh9NA//+hMbTd3cU9bx\nFPJ+pXostkehfKPReyoxjZQjwQYicAUKA8l1fMYyxBclTgp5Lvd0RC5+L9KRlgJM\n2QKBgGVIWRNVpGg38dDqdq/4ue1BoTFhqoMGi6WQm3xa+NH+lyJGacdUhGRz8PxN\nhVKpIj8ljg2Rq/CA9qSgL/Z9rhn8QUMWULuAroCp0S2pMBtZ2RB+Mg2FdVFR9/Ft\nfG7co6mKUGkFPtr48EMfeKY88BRsp3yGOsROGdDsCHItjOVH\n-----END RSA PRIVATE KEY-----\n"
|
46
41
|
|
47
|
-
# Returns the Public Key as a string
|
48
42
|
k.public_key
|
49
|
-
# => "-----BEGIN
|
43
|
+
# => "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvR7l72CT7UBP6P+02Iut\n8gKKbKyekz/pQxnckPp1VafuaIwCMvYfP4ffVJTcY5IhU9mISNxZf6YDQ0TuD1aO\nrZYG9wsIgGY0nXhOUZxe/Q5I+V7DOI/hSzKF7W0cNCvaJPUSo8+soCLNSQ5mjnV3\nsRZ6uJwGFN30i1GulqHHKkx3vGxbiaAL9YG58dPSbPGHFTA/epqUyd1fzCuWHyL9\ndHW7aw4RroNyEtVdiftAQfaK20I2ueeDfuEtCPaxQYFQqbz5kKnXQx3fwHRpC7/8\n4xHxsrY576evGxHw4p5EJD37scNNcneTG3Ly79/VVSAlrSm6ltutx0+S70scCqK0\newIDAQAB\n-----END PUBLIC KEY-----\n"
|
44
|
+
```
|
45
|
+
|
46
|
+
Fetch the SSH public key as a string.
|
50
47
|
|
51
|
-
|
48
|
+
```ruby
|
52
49
|
k.ssh_public_key
|
53
|
-
# => "ssh-rsa
|
50
|
+
# => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Encryption
|
54
|
+
|
55
|
+
If a passcode is set when a key is generated or by setting the `passcode` accessor, you can
|
56
|
+
fetch the encrypted version of the private key.
|
54
57
|
|
55
|
-
|
58
|
+
```ruby
|
59
|
+
k.passcode = "foo"
|
60
|
+
# => "foo"
|
61
|
+
|
62
|
+
k.encrypted_private_key
|
63
|
+
# => "-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: AES-128-CBC,748B766CFB185C3BD1D7E4D31113EBDA\n\ntWbfOuAjBlSZdq3kdJTLZJ7prjNWOKuGpeesNfVZDziIaZNCUakvgnUFdX3IZZnj\nEYITfjZ1TEUY3EkemL/57txiP3A4iOMDK2JGg8lp3G45x6c9XucJ2YxgvMye/ugP\n014MzLvBNunWq8TolkFj4gbc+WCqsyFqGdpRsf/hx7PcLDd2nvS5zxjBAPno87KN\nYgEnZYrpyl01ePucwFVWlrlGJdc0+F+0Ms5gpjMds56YL3Rwv9BlWzapVtrqN29r\nZg0otylPAyuGJOQ8srDOa+pbSySXvcdoKfR6xQ9fIB0tUfGgrH3c5O0/rEW7FSiO\n6ng4ntXXOKKkQfCezXQVvqMjKtKAbcKaPYAvrB2Gp2VIPUN5tN52nKuWvQWPA0P/\nm/uKiFkvzDWj8xMEOdzDAG9/7ysX+T5angvhfT23+NEdGIlPZLDRHI3f+2Itn99f\nvVoDYUXiyd5h7VwOTn6scebbvyPY8DiWpB/5iaU8WBPr7TVTl9n2z+Gmy4eg3wS0\nTU4hGlKv7MiITO2+dOCZTVrKn9/gTgmtyiLucb4huBH88Nsj4zWnTrVjMMBWsTUD\nkzvo9081zgDKKeawcbZYdI1Tc4epV7SMTHpx1ztzIlPdQ6kRaWomwMSarQeSlhJe\naFx67cde6M3Kc3LOgE0VT+3NvVLnkDwkytwnQKLd6oT3d1kFxWXjMwqiPbSzz3bf\nkOhG01gsJDXIzAgDlOlhE+Qlsd3yc734UIH98rTFMVB00HS36WLuz3hh+Ew4rsrf\nDIuRIdxL/4GVdQ8J5WpSoN0tF5iQD1wpEMU2vUjYjj9TZkhpOpnK3UVvbKd4WPsV\n956XJT7ZDvX4+pvHc5GJq/UX5h42kycY0hftUoLapXt5Nhb/fL8mUT8Eix184uiO\n5mA3fgRP3oGJ28N653X/+kL2YhXCeTd2VjkVhKruuoex96Igyt8W7wW5y7MOPezf\nwfo8IzidcJcDR1W4OEOXr+oDlCE1CLGCzmenR+AUIisqz45yb5G076l8PQkI3NWC\nBhT1YbTds4QzrndIDZgMm65ZCaklm+FVHWV61rXd9rlugcq+flQuXAE/EnFtySMc\n3lztrzXulLXzgLrYG355JbQFddwehO7LdxKZA9LHC9/odcoVI9RBj1CzshYtlftR\nn56nxPTIxRTVjQdgCZ6VcjZhwv1I904NtGm4SZupiShXsbHzAfaeJ54GMq4PRlgN\nmH7JrI9/puBb1dLD0XNgPtmYIo18v9e7g9o+un/wDtxCTxhQtD0npPo1IuW4cW7q\n07lZPwGkN2FD2PNTBGXeQ6/EXTHxlyFn62GSr+DmXu0O8MJS827Vd4b8QmKzRTxf\nFEmtVhiD15KlrQxwajmhqfY6KHRxbBuG/w7ioRr2Vl0G9NmKwmJkQO8dM+mJ8rVE\nsWvm8xVm1bowahzDVPnyFUUjuGNi6jFElkv8zvlQUoTcjSZHPrQSHuX742f5Spph\nLLCHdGZ2Ry8UGPlqKtvd6V/z25NsBgbuit+hNkBsdIztH7MVGAhKSMgk1FgXmKzV\nmZnPigq5WAHtIvojzI9NfZxU2Avif0yymXNtOnipw0sCJ0notN8NuGdQEmyxThqW\n-----END RSA PRIVATE KEY-----\n"
|
64
|
+
```
|
65
|
+
|
66
|
+
#### Comments
|
67
|
+
|
68
|
+
Keys can optionally have a comment that is shown as part of the public SSH key. Get or
|
69
|
+
set the key's comment with the `comment` accessor.
|
70
|
+
|
71
|
+
```ruby
|
56
72
|
k.comment
|
57
|
-
# =>
|
73
|
+
# => nil
|
74
|
+
|
75
|
+
k.comment = "me@me.com"
|
76
|
+
# => "me@me.com"
|
77
|
+
|
78
|
+
k.ssh_public_key
|
79
|
+
# => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7 me@me.com"
|
80
|
+
```
|
81
|
+
|
82
|
+
#### Bit length
|
83
|
+
|
84
|
+
Determine the strength of the key in bits as an integer.
|
58
85
|
|
59
|
-
|
86
|
+
```ruby
|
87
|
+
k.bits
|
88
|
+
# => 2048
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Fingerprints
|
92
|
+
|
93
|
+
It is often helpful to use a fingerprint to visually or programmatically check if one key
|
94
|
+
matches another. Fetch either an MD5 (OpenSSH default) or SHA1 fingerprint of the SSH public key.
|
95
|
+
|
96
|
+
```ruby
|
60
97
|
k.md5_fingerprint
|
61
98
|
# => "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
|
62
99
|
|
63
|
-
# Returns the SHA1 fingerprint as a string
|
64
100
|
k.sha1_fingerprint
|
65
101
|
# => "e4:f9:79:f2:fe:d6:be:2d:ef:2e:c2:fa:aa:f8:b0:17:34:fe:0d:c0"
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Public Key Directives
|
105
|
+
|
106
|
+
Add optional directives prefixed to the public key that will be enforced when a key is authenticated.
|
107
|
+
|
108
|
+
Accepts a string or an array of strings.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
k.directives = "no-pty"
|
112
|
+
# => ["no-pty"]
|
113
|
+
|
114
|
+
k.directives = [
|
115
|
+
"no-port-forwarding",
|
116
|
+
"no-X11-forwarding",
|
117
|
+
"no-agent-forwarding",
|
118
|
+
"no-pty",
|
119
|
+
"command='/home/user/bin/authprogs'"
|
120
|
+
]
|
121
|
+
# => ["no-port-forwarding", "no-X11-forwarding", "no-agent-forwarding", "no-pty", "command='/home/user/bin/authprogs'"]
|
122
|
+
|
123
|
+
k.ssh_public_key
|
124
|
+
# => "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command='/home/user/bin/authprogs' ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Randomart
|
128
|
+
|
129
|
+
Generate [OpenSSH compatible](http://www.opensource.apple.com/source/OpenSSH/OpenSSH-175/openssh/key.c) ASCII art fingerprints
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
puts k.randomart
|
133
|
+
+--[ RSA 2048]----+
|
134
|
+
|o+ o.. |
|
135
|
+
|..+.o |
|
136
|
+
| ooo |
|
137
|
+
|.++. o |
|
138
|
+
|+o+ + S |
|
139
|
+
|.. + o . |
|
140
|
+
| . + . |
|
141
|
+
| . . |
|
142
|
+
| Eo. |
|
143
|
+
+-----------------+
|
144
|
+
```
|
145
|
+
|
146
|
+
#### Original OpenSSL key object
|
147
|
+
|
148
|
+
Return the original [OpenSSL::PKey::RSA](http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/RSA.html) or [OpenSSL::PKey::DSA](http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/DSA.html) object.
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
k.key_object
|
152
|
+
# => -----BEGIN RSA PRIVATE KEY-----\nMIIEowI...
|
153
|
+
```
|
154
|
+
|
155
|
+
### Validate existing SSH public keys
|
156
|
+
|
157
|
+
Determine if a given SSH public key is valid. Very useful to test user input of public keys to make sure they accurately copy/pasted the key. Just pass the SSH public key as a string.
|
66
158
|
|
67
|
-
|
68
|
-
SSHKey.valid_ssh_public_key? "ssh-rsa
|
159
|
+
```ruby
|
160
|
+
SSHKey.valid_ssh_public_key? "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
69
161
|
# => true
|
70
162
|
```
|
71
163
|
|
72
|
-
Copyright
|
73
|
-
---------
|
164
|
+
## Copyright
|
74
165
|
|
75
166
|
Copyright (c) 2011-2013 James Miller
|
data/lib/sshkey.rb
CHANGED
@@ -7,9 +7,6 @@ class SSHKey
|
|
7
7
|
SSH_TYPES = {"rsa" => "ssh-rsa", "dsa" => "ssh-dss"}
|
8
8
|
SSH_CONVERSION = {"rsa" => ["e", "n"], "dsa" => ["p", "q", "g", "pub_key"]}
|
9
9
|
|
10
|
-
attr_reader :key_object, :type
|
11
|
-
attr_accessor :passphrase, :comment
|
12
|
-
|
13
10
|
class << self
|
14
11
|
# Generate a new keypair and return an SSHKey object
|
15
12
|
#
|
@@ -124,6 +121,9 @@ class SSHKey
|
|
124
121
|
end
|
125
122
|
end
|
126
123
|
|
124
|
+
attr_reader :key_object, :type
|
125
|
+
attr_accessor :passphrase, :comment
|
126
|
+
|
127
127
|
# Create a new SSHKey object
|
128
128
|
#
|
129
129
|
# ==== Parameters
|
@@ -131,10 +131,12 @@ class SSHKey
|
|
131
131
|
# * options<~Hash>
|
132
132
|
# * :comment<~String> - Comment to use for the public key, defaults to ""
|
133
133
|
# * :passphrase<~String> - If the key is encrypted, supply the passphrase
|
134
|
+
# * :directives<~Array> - Options prefixed to the public key
|
134
135
|
#
|
135
136
|
def initialize(private_key, options = {})
|
136
137
|
@passphrase = options[:passphrase]
|
137
138
|
@comment = options[:comment] || ""
|
139
|
+
self.directives = options[:directives]
|
138
140
|
begin
|
139
141
|
@key_object = OpenSSL::PKey::RSA.new(private_key, passphrase)
|
140
142
|
@type = "rsa"
|
@@ -172,7 +174,7 @@ class SSHKey
|
|
172
174
|
|
173
175
|
# SSH public key
|
174
176
|
def ssh_public_key
|
175
|
-
[SSH_TYPES[type], Base64.encode64(ssh_public_key_conversion).gsub("\n", ""), comment].join(" ").strip
|
177
|
+
[directives.join(",").strip, SSH_TYPES[type], Base64.encode64(ssh_public_key_conversion).gsub("\n", ""), comment].join(" ").strip
|
176
178
|
end
|
177
179
|
|
178
180
|
# Fingerprints
|
@@ -250,6 +252,11 @@ class SSHKey
|
|
250
252
|
output
|
251
253
|
end
|
252
254
|
|
255
|
+
def directives=(directives)
|
256
|
+
@directives = Array[directives].flatten
|
257
|
+
end
|
258
|
+
attr_reader :directives
|
259
|
+
|
253
260
|
private
|
254
261
|
|
255
262
|
# SSH Public Key Conversion
|
data/lib/sshkey/version.rb
CHANGED
data/test/sshkey_test.rb
CHANGED
@@ -202,12 +202,36 @@ EOF
|
|
202
202
|
assert_equal expected4, @key_without_comment.ssh_public_key
|
203
203
|
end
|
204
204
|
|
205
|
+
def test_public_key_directives
|
206
|
+
@key1.directives = "no-pty"
|
207
|
+
assert_equal ["no-pty"], @key1.directives
|
208
|
+
|
209
|
+
@key1.directives = ["no-pty"]
|
210
|
+
assert_equal ["no-pty"], @key1.directives
|
211
|
+
|
212
|
+
@key1.directives = [
|
213
|
+
"no-port-forwarding",
|
214
|
+
"no-X11-forwarding",
|
215
|
+
"no-agent-forwarding",
|
216
|
+
"no-pty",
|
217
|
+
"command='/home/user/bin/authprogs'"
|
218
|
+
]
|
219
|
+
expected1 = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command='/home/user/bin/authprogs' ssh-rsa #{SSH_PUBLIC_KEY1} me@example.com"
|
220
|
+
assert_equal expected1, @key1.ssh_public_key
|
221
|
+
assert SSHKey.valid_ssh_public_key?(expected1)
|
222
|
+
|
223
|
+
@key2.directives = "no-pty"
|
224
|
+
expected2 = "no-pty ssh-rsa #{SSH_PUBLIC_KEY2} me@example.com"
|
225
|
+
assert_equal expected2, @key2.ssh_public_key
|
226
|
+
assert SSHKey.valid_ssh_public_key?(expected2)
|
227
|
+
end
|
228
|
+
|
205
229
|
def test_ssh_public_key_validation
|
206
230
|
expected1 = "ssh-rsa #{SSH_PUBLIC_KEY1} me@example.com"
|
207
231
|
expected2 = "ssh-rsa #{SSH_PUBLIC_KEY2} me@example.com"
|
208
232
|
expected3 = "ssh-dss #{SSH_PUBLIC_KEY3} me@example.com"
|
209
233
|
expected4 = "ssh-rsa #{SSH_PUBLIC_KEY1}"
|
210
|
-
expected5 = %Q{from="trusted.eng.cam.ac.uk",no-port-forwarding,no-pty
|
234
|
+
expected5 = %Q{from="trusted.eng.cam.ac.uk",no-port-forwarding,no-pty ssh-rsa #{SSH_PUBLIC_KEY1}}
|
211
235
|
invalid1 = "ssh-rsa #{SSH_PUBLIC_KEY1}= me@example.com"
|
212
236
|
invalid2 = "ssh-rsa #{SSH_PUBLIC_KEY2}= me@example.com"
|
213
237
|
invalid3 = "ssh-dss #{SSH_PUBLIC_KEY3}= me@example.com"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -70,3 +70,4 @@ specification_version: 3
|
|
70
70
|
summary: SSH private/public key generator in Ruby
|
71
71
|
test_files:
|
72
72
|
- test/sshkey_test.rb
|
73
|
+
has_rdoc:
|