Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caucase
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
caucase
Commits
1a10a495
Commit
1a10a495
authored
Nov 04, 2017
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all: Word-wrap.
parent
411d5b66
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
25 deletions
+67
-25
caucase/ca.py
caucase/ca.py
+24
-11
caucase/cli.py
caucase/cli.py
+21
-7
caucase/http.py
caucase/http.py
+6
-2
caucase/storage.py
caucase/storage.py
+6
-1
caucase/test.py
caucase/test.py
+5
-2
caucase/utils.py
caucase/utils.py
+3
-1
caucase/wsgi.py
caucase/wsgi.py
+2
-1
No files found.
caucase/ca.py
View file @
1a10a495
...
@@ -167,7 +167,10 @@ class CertificateAuthority(object):
...
@@ -167,7 +167,10 @@ class CertificateAuthority(object):
])
])
if
ca_life_period
<
3
:
if
ca_life_period
<
3
:
raise
ValueError
(
"ca_life_period must be >= 3 to allow CA rollout"
)
raise
ValueError
(
"ca_life_period must be >= 3 to allow CA rollout"
)
self
.
_crl_life_time
=
datetime
.
timedelta
(
crt_life_time
*
crl_renew_period
,
0
)
self
.
_crl_life_time
=
datetime
.
timedelta
(
crt_life_time
*
crl_renew_period
,
0
,
)
self
.
_ca_life_time
=
datetime
.
timedelta
(
crt_life_time
*
ca_life_period
,
0
)
self
.
_ca_life_time
=
datetime
.
timedelta
(
crt_life_time
*
ca_life_period
,
0
)
self
.
_loadCAKeyPairList
()
self
.
_loadCAKeyPairList
()
self
.
_renewCAIfNeeded
()
self
.
_renewCAIfNeeded
()
...
@@ -182,7 +185,10 @@ class CertificateAuthority(object):
...
@@ -182,7 +185,10 @@ class CertificateAuthority(object):
def
_loadCAKeyPairList
(
self
):
def
_loadCAKeyPairList
(
self
):
ca_key_pair_list
=
[]
ca_key_pair_list
=
[]
for
pem_key_pair
in
self
.
_storage
.
getCAKeyPairList
():
for
pem_key_pair
in
self
.
_storage
.
getCAKeyPairList
():
utils
.
validateCertAndKey
(
pem_key_pair
[
'crt_pem'
],
pem_key_pair
[
'key_pem'
])
utils
.
validateCertAndKey
(
pem_key_pair
[
'crt_pem'
],
pem_key_pair
[
'key_pem'
],
)
ca_key_pair_list
.
append
({
ca_key_pair_list
.
append
({
'crt'
:
utils
.
load_ca_certificate
(
pem_key_pair
[
'crt_pem'
]),
'crt'
:
utils
.
load_ca_certificate
(
pem_key_pair
[
'crt_pem'
]),
'key'
:
utils
.
load_privatekey
(
pem_key_pair
[
'key_pem'
]),
'key'
:
utils
.
load_privatekey
(
pem_key_pair
[
'key_pem'
]),
...
@@ -302,7 +308,9 @@ class CertificateAuthority(object):
...
@@ -302,7 +308,9 @@ class CertificateAuthority(object):
),
),
Extension
(
Extension
(
x509
.
AuthorityKeyIdentifier
.
from_issuer_subject_key_identifier
(
x509
.
AuthorityKeyIdentifier
.
from_issuer_subject_key_identifier
(
ca_crt
.
extensions
.
get_extension_for_class
(
x509
.
SubjectKeyIdentifier
),
ca_crt
.
extensions
.
get_extension_for_class
(
x509
.
SubjectKeyIdentifier
,
),
),
),
critical
=
False
,
# "MUST mark this extension as non-critical"
critical
=
False
,
# "MUST mark this extension as non-critical"
),
),
...
@@ -349,7 +357,8 @@ class CertificateAuthority(object):
...
@@ -349,7 +357,8 @@ class CertificateAuthority(object):
decipher_only
=
decipher_only
,
decipher_only
=
decipher_only
,
# pylint: enable=bad-whitespace
# pylint: enable=bad-whitespace
),
),
critical
=
key_usage_extension
.
critical
,
# "SHOULD mark this extension critical"
# "SHOULD mark this extension critical"
critical
=
key_usage_extension
.
critical
,
)
)
try
:
try
:
extended_key_usage
=
template_csr
.
extensions
.
get_extension_for_class
(
extended_key_usage
=
template_csr
.
extensions
.
get_extension_for_class
(
...
@@ -403,7 +412,9 @@ class CertificateAuthority(object):
...
@@ -403,7 +412,9 @@ class CertificateAuthority(object):
# "auto-signed" one...
# "auto-signed" one...
policy_list
=
[
policy_list
=
[
x
for
x
in
certificate_policies
.
value
x
for
x
in
certificate_policies
.
value
if
not
x
.
policy_identifier
.
dotted_string
.
startswith
(
utils
.
CAUCASE_OID_TOP
)
if
not
x
.
policy_identifier
.
dotted_string
.
startswith
(
utils
.
CAUCASE_OID_TOP
,
)
]
]
if
auto_signed
==
_AUTO_SIGNED_YES
:
if
auto_signed
==
_AUTO_SIGNED_YES
:
# ...but do add auto-signed extension if we are auto-signing.
# ...but do add auto-signed extension if we are auto-signing.
...
@@ -438,7 +449,8 @@ class CertificateAuthority(object):
...
@@ -438,7 +449,8 @@ class CertificateAuthority(object):
"""
"""
if
(
if
(
self
.
_ca_key_size
is
not
None
and
not
self
.
_ca_key_pairs_list
or
(
self
.
_ca_key_size
is
not
None
and
not
self
.
_ca_key_pairs_list
or
(
self
.
_ca_key_pairs_list
[
-
1
][
'crt'
].
not_valid_after
-
datetime
.
datetime
.
utcnow
()
self
.
_ca_key_pairs_list
[
-
1
][
'crt'
].
not_valid_after
-
datetime
.
datetime
.
utcnow
()
).
total_seconds
()
/
self
.
_crt_life_time
.
total_seconds
()
<=
2
).
total_seconds
()
/
self
.
_crt_life_time
.
total_seconds
()
<=
2
)
and
self
.
_ca_renewal_lock
.
acquire
(
False
):
)
and
self
.
_ca_renewal_lock
.
acquire
(
False
):
try
:
try
:
...
@@ -510,7 +522,8 @@ class CertificateAuthority(object):
...
@@ -510,7 +522,8 @@ class CertificateAuthority(object):
),
),
Extension
(
Extension
(
x509
.
AuthorityKeyIdentifier
.
from_issuer_subject_key_identifier
(
x509
.
AuthorityKeyIdentifier
.
from_issuer_subject_key_identifier
(
# Dummy extension, from_issuer_subject_key_identifier accesses .data directly
# Dummy extension, from_issuer_subject_key_identifier accesses
# .data directly
Extension
(
Extension
(
subject_key_identifier
,
subject_key_identifier
,
critical
=
False
,
critical
=
False
,
...
@@ -520,8 +533,8 @@ class CertificateAuthority(object):
...
@@ -520,8 +533,8 @@ class CertificateAuthority(object):
),
),
],
],
)
)
# Copy all extensions, except the ones which depend on the key (and
which
# Copy all extensions, except the ones which depend on the key (and
# we just set).
# w
hich w
e just set).
skipped_extension_oid_set
=
(
skipped_extension_oid_set
=
(
x509
.
SubjectKeyIdentifier
.
oid
,
x509
.
SubjectKeyIdentifier
.
oid
,
x509
.
AuthorityKeyIdentifier
.
oid
,
x509
.
AuthorityKeyIdentifier
.
oid
,
...
@@ -567,8 +580,8 @@ class CertificateAuthority(object):
...
@@ -567,8 +580,8 @@ class CertificateAuthority(object):
# using it.
# using it.
break
break
else
:
else
:
# No CA cert is valid for more than one certificate life time, so just
pick
# No CA cert is valid for more than one certificate life time, so just
# the newest one.
#
pick
the newest one.
key_pair
=
self
.
_ca_key_pairs_list
[
-
1
]
key_pair
=
self
.
_ca_key_pairs_list
[
-
1
]
return
key_pair
return
key_pair
...
...
caucase/cli.py
View file @
1a10a495
...
@@ -92,7 +92,7 @@ class CLICaucaseClient(object):
...
@@ -92,7 +92,7 @@ class CLICaucaseClient(object):
except
CaucaseError
,
e
:
except
CaucaseError
,
e
:
if
e
.
args
[
0
]
!=
httplib
.
NOT_FOUND
:
if
e
.
args
[
0
]
!=
httplib
.
NOT_FOUND
:
raise
raise
print
crt_id
,
'not found -
either csr id has a typo or CSR was rejected
'
print
crt_id
,
'not found -
maybe CSR was rejected ?
'
error
=
True
error
=
True
else
:
else
:
print
crt_id
,
'CSR still pending'
print
crt_id
,
'CSR still pending'
...
@@ -175,7 +175,11 @@ class CLICaucaseClient(object):
...
@@ -175,7 +175,11 @@ class CLICaucaseClient(object):
error
=
True
error
=
True
continue
continue
try
:
try
:
old_crt
=
utils
.
load_certificate
(
old_crt_pem
,
ca_certificate_list
,
None
)
old_crt
=
utils
.
load_certificate
(
old_crt_pem
,
ca_certificate_list
,
None
,
)
except
exceptions
.
CertificateVerificationError
:
except
exceptions
.
CertificateVerificationError
:
print
crt_path
,
(
print
crt_path
,
(
'was not signed by this CA, revoked or otherwise invalid, skipping'
'was not signed by this CA, revoked or otherwise invalid, skipping'
...
@@ -278,7 +282,8 @@ def main(argv=None):
...
@@ -278,7 +282,8 @@ def main(argv=None):
Command line caucase client entry point.
Command line caucase client entry point.
"""
"""
parser
=
argparse
.
ArgumentParser
(
description
=
'caucase'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'caucase'
)
# XXX: currently, it is the server which chooses which digest is used to sign stuff.
# XXX: currently, it is the server which chooses which digest is used to sign
# stuff.
# Should clients be able to tell it how to sign (and server could reject) ?
# Should clients be able to tell it how to sign (and server could reject) ?
parser
.
add_argument
(
parser
.
add_argument
(
'--ca-url'
,
'--ca-url'
,
...
@@ -657,8 +662,9 @@ def updater(argv=None):
...
@@ -657,8 +662,9 @@ def updater(argv=None):
'--key'
,
'--key'
,
metavar
=
'KEY_PATH'
,
metavar
=
'KEY_PATH'
,
help
=
'Path of your private key file. Must always exist when this command '
help
=
'Path of your private key file. Must always exist when this command '
'is started. Will be updated on certificate renewal. If not provided, both '
'is started. Will be updated on certificate renewal. If not provided, '
'key and certificate will be stored in the file pointed at by --crt .'
,
'both key and certificate will be stored in the file pointed at by '
'--crt .'
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
'--crt'
,
'--crt'
,
...
@@ -756,7 +762,13 @@ def updater(argv=None):
...
@@ -756,7 +762,13 @@ def updater(argv=None):
crt_file
.
write
(
new_key_pem
)
crt_file
.
write
(
new_key_pem
)
crt_file
.
write
(
new_crt_pem
)
crt_file
.
write
(
new_crt_pem
)
else
:
else
:
with
open
(
args
.
crt
,
'w'
)
as
crt_file
,
open
(
key_path
,
'w'
)
as
key_file
:
with
open
(
args
.
crt
,
'w'
,
)
as
crt_file
,
open
(
key_path
,
'w'
,
)
as
key_file
:
key_file
.
write
(
new_key_pem
)
key_file
.
write
(
new_key_pem
)
crt_file
.
write
(
new_crt_pem
)
crt_file
.
write
(
new_crt_pem
)
updated
=
True
updated
=
True
...
@@ -812,7 +824,9 @@ def rerequest(argv=None):
...
@@ -812,7 +824,9 @@ def rerequest(argv=None):
'default: %(default)s'
,
'default: %(default)s'
,
)
)
args
=
parser
.
parse_args
(
argv
)
args
=
parser
.
parse_args
(
argv
)
template
=
utils
.
load_certificate_request
(
utils
.
getCertRequest
(
args
.
template
))
template
=
utils
.
load_certificate_request
(
utils
.
getCertRequest
(
args
.
template
),
)
key
=
utils
.
generatePrivateKey
(
key_len
=
args
.
key_len
)
key
=
utils
.
generatePrivateKey
(
key_len
=
args
.
key_len
)
csr_pem
=
utils
.
dump_certificate_request
(
csr_pem
=
utils
.
dump_certificate_request
(
x509
.
CertificateSigningRequestBuilder
(
x509
.
CertificateSigningRequestBuilder
(
...
...
caucase/http.py
View file @
1a10a495
...
@@ -76,7 +76,9 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
...
@@ -76,7 +76,9 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
def
__init__
(
self
,
server_address
,
*
args
,
**
kw
):
def
__init__
(
self
,
server_address
,
*
args
,
**
kw
):
self
.
address_family
,
_
,
_
,
_
,
_
=
socket
.
getaddrinfo
(
*
server_address
)[
0
]
self
.
address_family
,
_
,
_
,
_
,
_
=
socket
.
getaddrinfo
(
*
server_address
)[
0
]
assert
self
.
address_family
in
(
socket
.
AF_INET
,
socket
.
AF_INET6
),
self
.
address_family
assert
self
.
address_family
in
(
socket
.
AF_INET
,
socket
.
AF_INET6
),
(
self
.
address_family
,
)
WSGIServer
.
__init__
(
self
,
server_address
,
*
args
,
**
kw
)
WSGIServer
.
__init__
(
self
,
server_address
,
*
args
,
**
kw
)
class
CaucaseWSGIRequestHandler
(
WSGIRequestHandler
):
class
CaucaseWSGIRequestHandler
(
WSGIRequestHandler
):
...
@@ -94,7 +96,9 @@ class CaucaseWSGIRequestHandler(WSGIRequestHandler):
...
@@ -94,7 +96,9 @@ class CaucaseWSGIRequestHandler(WSGIRequestHandler):
timezone (including DST considerations), time it always logged in GMT
timezone (including DST considerations), time it always logged in GMT
"""
"""
now
=
datetime
.
datetime
.
utcnow
()
now
=
datetime
.
datetime
.
utcnow
()
return
now
.
strftime
(
'%d/'
+
self
.
monthname
[
now
.
month
]
+
'/%Y:%H:%M:%S +0000'
)
return
now
.
strftime
(
'%d/'
+
self
.
monthname
[
now
.
month
]
+
'/%Y:%H:%M:%S +0000'
,
)
class
CaucaseSSLWSGIRequestHandler
(
CaucaseWSGIRequestHandler
):
class
CaucaseSSLWSGIRequestHandler
(
CaucaseWSGIRequestHandler
):
"""
"""
...
...
caucase/storage.py
View file @
1a10a495
...
@@ -227,7 +227,12 @@ class SQLite3Storage(local):
...
@@ -227,7 +227,12 @@ class SQLite3Storage(local):
),
),
)
)
def
appendCertificateSigningRequest
(
self
,
csr_pem
,
key_id
,
override_limits
=
False
):
def
appendCertificateSigningRequest
(
self
,
csr_pem
,
key_id
,
override_limits
=
False
,
):
"""
"""
Store acertificate signing request and generate a unique ID for it.
Store acertificate signing request and generate a unique ID for it.
Note: ID uniqueness is only guaranteed among pending CSR, and may be reused
Note: ID uniqueness is only guaranteed among pending CSR, and may be reused
...
...
caucase/test.py
View file @
1a10a495
...
@@ -109,7 +109,10 @@ class CaucaseTest(unittest.TestCase):
...
@@ -109,7 +109,10 @@ class CaucaseTest(unittest.TestCase):
# pylint: enable=bad-whitespace
# pylint: enable=bad-whitespace
os
.
mkdir
(
self
.
_server_backup_path
)
os
.
mkdir
(
self
.
_server_backup_path
)
self
.
_server_netloc
=
netloc
=
os
.
getenv
(
'CAUCASE_NETLOC'
,
'localhost:8000'
)
self
.
_server_netloc
=
netloc
=
os
.
getenv
(
'CAUCASE_NETLOC'
,
'localhost:8000'
,
)
self
.
_caucase_url
=
'http://'
+
netloc
self
.
_caucase_url
=
'http://'
+
netloc
parsed_url
=
urlparse
.
urlparse
(
self
.
_caucase_url
)
parsed_url
=
urlparse
.
urlparse
(
self
.
_caucase_url
)
self
.
assertFalse
(
self
.
assertFalse
(
...
@@ -706,7 +709,7 @@ class CaucaseTest(unittest.TestCase):
...
@@ -706,7 +709,7 @@ class CaucaseTest(unittest.TestCase):
).
splitlines
()
).
splitlines
()
self
.
assertRaises
(
TypeError
,
utils
.
getCert
,
key_path
)
self
.
assertRaises
(
TypeError
,
utils
.
getCert
,
key_path
)
self
.
assertEqual
([
self
.
assertEqual
([
csr_id
+
' not found -
either csr id has a typo or CSR was rejected
'
csr_id
+
' not found -
maybe CSR was rejected ?
'
],
out
)
],
out
)
def
testBadCSR
(
self
):
def
testBadCSR
(
self
):
...
...
caucase/utils.py
View file @
1a10a495
...
@@ -218,7 +218,9 @@ def _verifyCertificateChain(cert, trusted_cert_list, crl):
...
@@ -218,7 +218,9 @@ def _verifyCertificateChain(cert, trusted_cert_list, crl):
crypto
.
X509StoreContextError
,
crypto
.
X509StoreContextError
,
crypto
.
Error
,
crypto
.
Error
,
),
e
:
),
e
:
raise
CertificateVerificationError
(
'Certificate verification error: %s'
%
str
(
e
))
raise
CertificateVerificationError
(
'Certificate verification error: %s'
%
str
(
e
),
)
def
wrap
(
payload
,
key
,
digest
):
def
wrap
(
payload
,
key
,
digest
):
"""
"""
...
...
caucase/wsgi.py
View file @
1a10a495
...
@@ -98,7 +98,8 @@ class InsufficientStorage(ApplicationError):
...
@@ -98,7 +98,8 @@ class InsufficientStorage(ApplicationError):
"""
"""
No storage slot available (not necessarily out of disk space)
No storage slot available (not necessarily out of disk space)
"""
"""
# httplib lacks the textual description for 507, although it has the constant...
# httplib lacks the textual description for 507, although it has the
# constant...
status
=
'%i Insufficient Storage'
%
(
httplib
.
INSUFFICIENT_STORAGE
,
)
status
=
'%i Insufficient Storage'
%
(
httplib
.
INSUFFICIENT_STORAGE
,
)
STATUS_OK
=
_getStatus
(
httplib
.
OK
)
STATUS_OK
=
_getStatus
(
httplib
.
OK
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment