This repository was archived by the owner on Sep 12, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 7
7
before_install :
8
8
- sudo apt-get update
9
9
- sudo apt-get install redis-server
10
- - sudo apt-get install libevent-dev liblzma-dev
10
+ - sudo apt-get install libevent-dev liblzma-dev libssl-dev
11
+ - sudo apt-get install swig
11
12
12
13
install :
13
14
# # This below should be separated when core lives elsewhere
Original file line number Diff line number Diff line change 2
2
3
3
import os
4
4
5
- import rsa
5
+ from M2Crypto import BIO
6
+ from M2Crypto import RSA
6
7
import yaml
7
8
8
9
from docker_registry .core import compat
@@ -109,10 +110,17 @@ def _init():
109
110
'Heads-up! File is missing: %s' % conf .privileged_key )
110
111
111
112
try :
112
- conf .privileged_key = rsa .PublicKey .load_pkcs1 (f .read ())
113
+ pk = f .read ().split ('\n ' )
114
+ pk = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' + '' .join (pk [1 :- 2 ])
115
+ pk = [pk [i : i + 64 ] for i in range (0 , len (pk ), 64 )]
116
+ pk = ('-----BEGIN PUBLIC KEY-----\n ' + '\n ' .join (pk ) +
117
+ '\n -----END PUBLIC KEY-----' )
118
+ bio = BIO .MemoryBuffer (pk )
119
+ conf .privileged_key = RSA .load_pub_key_bio (bio )
113
120
except Exception :
114
121
raise exceptions .ConfigError (
115
122
'Key at %s is not a valid RSA key' % conf .privileged_key )
123
+ f .close ()
116
124
117
125
if conf .index_endpoint :
118
126
conf .index_endpoint = conf .index_endpoint .strip ('/' )
Original file line number Diff line number Diff line change 2
2
3
3
import base64
4
4
import functools
5
+ import hashlib
5
6
import logging
6
7
import os
7
8
import random
10
11
import urllib
11
12
12
13
import flask
14
+ from M2Crypto import RSA
13
15
import requests
14
- import rsa
15
16
16
17
from docker_registry .core import compat
17
18
json = compat .json
20
21
from .lib import config
21
22
22
23
cfg = config .load ()
24
+
23
25
logger = logging .getLogger (__name__ )
24
26
_re_docker_version = re .compile ('docker/([^\s]+)' )
25
27
_re_authorization = re .compile (r'(\w+)[:=][\s"]?([^",]+)"?' )
@@ -221,7 +223,8 @@ def check_token(args):
221
223
222
224
223
225
def check_signature ():
224
- if not cfg .privileged_key :
226
+ pkey = cfg .privileged_key
227
+ if not pkey :
225
228
return False
226
229
headers = flask .request .headers
227
230
signature = headers .get ('X-Signature' )
@@ -238,8 +241,9 @@ def check_signature():
238
241
['{}:{}' .format (k , headers [k ]) for k in header_keys ])
239
242
logger .debug ('Signed message: {}' .format (message ))
240
243
try :
241
- return rsa .verify (message , sigdata , cfg .privileged_key )
242
- except rsa .VerificationError :
244
+ return pkey .verify (message_digest (message ), sigdata , 'sha1' )
245
+ except RSA .RSAError as e :
246
+ logger .exception (e )
243
247
return False
244
248
245
249
@@ -251,6 +255,12 @@ def parse_content_signature(s):
251
255
return ret
252
256
253
257
258
+ def message_digest (s ):
259
+ m = hashlib .new ('sha1' )
260
+ m .update (s )
261
+ return m .digest ()
262
+
263
+
254
264
def requires_auth (f ):
255
265
@functools .wraps (f )
256
266
def wrapper (* args , ** kwargs ):
Original file line number Diff line number Diff line change @@ -4,6 +4,6 @@ gevent==1.0.1
4
4
gunicorn==19.1
5
5
PyYAML==3.11
6
6
requests==2.3.0
7
- rsa==3.1.4
7
+ M2Crypto==0.22.3
8
8
sqlalchemy==0.9.4
9
9
setuptools==5.8
You can’t perform that action at this time.
0 commit comments