theca 2.0.3__tar.gz → 3.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
theca-3.0.2/PKG-INFO ADDED
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: theca
3
+ Version: 3.0.2
4
+ Summary: Python library to run your own private CA (devnull.cn/theca).
5
+ Home-page: https://devnull.cn
6
+ Author: Xizhen Du
7
+ Author-email: xizhendu@gmail.com
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: requests~=2.31.0
11
+ Requires-Dist: theid>=2
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: description
15
+ Dynamic: description-content-type
16
+ Dynamic: home-page
17
+ Dynamic: license-file
18
+ Dynamic: requires-dist
19
+ Dynamic: summary
20
+
21
+ # theca-sdk-python
22
+
23
+ Run your own private CA at [devnull.cn](https://devnull.cn/pca): the service
24
+ signs a per-account root CA and SAN certificates, and this package writes the
25
+ PEM files to `~/.devnull/certs/`.
26
+
27
+ Requires `theid>=2` (theid 2.0 credentials; the service only accepts EdDSA
28
+ access tokens).
29
+
30
+ ## Usage
31
+
32
+ ```bash
33
+ # Credentials come from ~/.devnull/credentials (shared with devnull-cli) or env
34
+ export THEID_ACCESS_KEY=DK...
35
+ export THEID_SECRET_KEY=...
36
+
37
+ python3 - <<'EOF'
38
+ from theca import create_cert
39
+ print(create_cert())
40
+ EOF
41
+
42
+ ls -lt ~/.devnull/certs/
43
+ # key.pem crt.pem fullchain.pem ca.pem system_id subject_alternative_names properties
44
+ ```
45
+
46
+ `create_cert()` creates the account's root CA on first use, then issues a
47
+ certificate for the host's `system_id` plus its `private`/`public` thedns
48
+ names, and writes the chain next to it. The returned `ca_url`
49
+ (`https://devnull.cn/getca/<orgid>`) downloads the CA certificate.
50
+
51
+ Point at another environment with `DEVNULL_PCA_URL`
52
+ (default `https://devnull.cn/pca`; the 3.0.1 name `DEVNULL_THECA_URL` is still read). The identity service is resolved by
53
+ `theid` (`DEVNULL_BASE_URL` / `THEID_ISSUER`).
54
+
55
+ ## What the service stores
56
+
57
+ Per account: one RSA-4096 root CA (10 years) and up to 11 RSA-2048
58
+ certificates (1 year, SANs from the requested names). All material is stored
59
+ in Postgres as base64 PEM; `create_cert()` is idempotent per common name.
theca-3.0.2/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # theca-sdk-python
2
+
3
+ Run your own private CA at [devnull.cn](https://devnull.cn/pca): the service
4
+ signs a per-account root CA and SAN certificates, and this package writes the
5
+ PEM files to `~/.devnull/certs/`.
6
+
7
+ Requires `theid>=2` (theid 2.0 credentials; the service only accepts EdDSA
8
+ access tokens).
9
+
10
+ ## Usage
11
+
12
+ ```bash
13
+ # Credentials come from ~/.devnull/credentials (shared with devnull-cli) or env
14
+ export THEID_ACCESS_KEY=DK...
15
+ export THEID_SECRET_KEY=...
16
+
17
+ python3 - <<'EOF'
18
+ from theca import create_cert
19
+ print(create_cert())
20
+ EOF
21
+
22
+ ls -lt ~/.devnull/certs/
23
+ # key.pem crt.pem fullchain.pem ca.pem system_id subject_alternative_names properties
24
+ ```
25
+
26
+ `create_cert()` creates the account's root CA on first use, then issues a
27
+ certificate for the host's `system_id` plus its `private`/`public` thedns
28
+ names, and writes the chain next to it. The returned `ca_url`
29
+ (`https://devnull.cn/getca/<orgid>`) downloads the CA certificate.
30
+
31
+ Point at another environment with `DEVNULL_PCA_URL`
32
+ (default `https://devnull.cn/pca`; the 3.0.1 name `DEVNULL_THECA_URL` is still read). The identity service is resolved by
33
+ `theid` (`DEVNULL_BASE_URL` / `THEID_ISSUER`).
34
+
35
+ ## What the service stores
36
+
37
+ Per account: one RSA-4096 root CA (10 years) and up to 11 RSA-2048
38
+ certificates (1 year, SANs from the requested names). All material is stored
39
+ in Postgres as base64 PEM; `create_cert()` is idempotent per common name.
@@ -2,16 +2,16 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='theca',
5
- version='2.0.3',
5
+ version='3.0.2',
6
6
  author='Xizhen Du',
7
7
  author_email='xizhendu@gmail.com',
8
8
  url='https://devnull.cn',
9
9
  long_description=open('README.md', 'r').read(),
10
10
  long_description_content_type='text/markdown',
11
- description='Python library to run your own private CA.',
11
+ description='Python library to run your own private CA (devnull.cn/theca).',
12
12
  # packages=['thedns'],
13
13
  install_requires=[
14
14
  "requests~=2.31.0",
15
- "theid"
15
+ "theid>=2"
16
16
  ]
17
17
  )
@@ -1,6 +1,6 @@
1
1
  import pathlib
2
2
  import base64
3
- from theid import authorization_headers, system_id, email
3
+ from theid import account_id, authorization_headers, system_id
4
4
 
5
5
  # from .auth import _token
6
6
  # from .auth import _credentials
@@ -20,7 +20,9 @@ from ._utils import _create_cert
20
20
  # _request_headers = _request_headers(token=_token)
21
21
  # _system_id = _get_fqdn_id()
22
22
  _system_id = system_id()
23
- _common_names = [ _system_id, _system_id + '.private.thedns.cn', _system_id + '.public.thedns.cn']
23
+ # The bare system_id is a 64-hex string, which is longer than a DNS label
24
+ # (63); the CA service validates names, so only request the two FQDNs.
25
+ _common_names = [_system_id + '.private.thedns.cn', _system_id + '.public.thedns.cn']
24
26
 
25
27
  def __create_ca():
26
28
  return _create_ca(request_headers=authorization_headers())
@@ -64,7 +66,7 @@ def create_cert():
64
66
  # f.write(ca_id)
65
67
  with properties_file.open('wt') as f:
66
68
  f.write(f"ca_id: {ca_id}\n"
67
- f"ca_owner: {email()}\n"
69
+ f"ca_owner: {account_id()}\n"
68
70
  f"system_id: {_system_id}\n"
69
71
  f"signed_sans: {' '.join(_common_names)}\n"
70
72
  )
@@ -1,8 +1,15 @@
1
1
  import json
2
+ import os
2
3
  import requests
3
4
  import socket
4
5
  import hashlib
5
6
 
7
+ # The private CA service. The public path is /pca (the CA is not trusted by a
8
+ # public root); /theca remains only for the 3.0.1 release. Overridable.
9
+ THECA_URL = (os.environ.get('DEVNULL_PCA_URL')
10
+ or os.environ.get('DEVNULL_THECA_URL')
11
+ or 'https://devnull.cn/pca').rstrip('/')
12
+
6
13
  def _get_private_ip():
7
14
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
8
15
  s.connect(('8.8.8.8', 80))
@@ -24,7 +31,7 @@ def _get_ca(request_headers=None):
24
31
  "cert_type": 'root'
25
32
  })
26
33
  print(f"Headers: {request_headers}")
27
- response = requests.post('https://devnull.cn/pca', headers=request_headers, data=payload)
34
+ response = requests.post(THECA_URL, headers=request_headers, data=payload)
28
35
  return response.json()
29
36
 
30
37
  def _get_certs(request_headers=None):
@@ -32,7 +39,7 @@ def _get_certs(request_headers=None):
32
39
  "action_type": 'list',
33
40
  })
34
41
  print(f"Headers: {request_headers}")
35
- response = requests.post('https://devnull.cn/pca', headers=request_headers, data=payload)
42
+ response = requests.post(THECA_URL, headers=request_headers, data=payload)
36
43
  return response.json()
37
44
 
38
45
 
@@ -42,7 +49,7 @@ def _create_ca(request_headers=None):
42
49
  "action_type": 'read',
43
50
  "cert_type": 'root'
44
51
  })
45
- response = requests.post('https://devnull.cn/pca', headers=request_headers, data=payload)
52
+ response = requests.post(THECA_URL, headers=request_headers, data=payload)
46
53
  if response.json()['rc'] == 200:
47
54
  # print(f"Private CA exists...")
48
55
  return response.json()
@@ -52,7 +59,7 @@ def _create_ca(request_headers=None):
52
59
  "action_type": 'create',
53
60
  "cert_type": "root"
54
61
  })
55
- response = requests.post('https://devnull.cn/pca', headers=request_headers, data=payload)
62
+ response = requests.post(THECA_URL, headers=request_headers, data=payload)
56
63
  return response.json()
57
64
 
58
65
  # def _create_cert_disabled(request_headers=None, common_name=None):
@@ -61,7 +68,7 @@ def _create_ca(request_headers=None):
61
68
  # 'cert_type': 'common',
62
69
  # 'common_name': common_name
63
70
  # })
64
- # response = requests.post('https://devnull.cn/pca', headers=request_headers, data=payload)
71
+ # response = requests.post(THECA_URL, headers=request_headers, data=payload)
65
72
  # return response.json()
66
73
 
67
74
  def _create_cert(request_headers=None, common_names=None):
@@ -71,5 +78,5 @@ def _create_cert(request_headers=None, common_names=None):
71
78
  'cert_type': 'common',
72
79
  'common_names': common_names
73
80
  })
74
- response = requests.post('https://devnull.cn/pca', headers=request_headers, data=payload)
81
+ response = requests.post(THECA_URL, headers=request_headers, data=payload)
75
82
  return response.json()
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: theca
3
+ Version: 3.0.2
4
+ Summary: Python library to run your own private CA (devnull.cn/theca).
5
+ Home-page: https://devnull.cn
6
+ Author: Xizhen Du
7
+ Author-email: xizhendu@gmail.com
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: requests~=2.31.0
11
+ Requires-Dist: theid>=2
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: description
15
+ Dynamic: description-content-type
16
+ Dynamic: home-page
17
+ Dynamic: license-file
18
+ Dynamic: requires-dist
19
+ Dynamic: summary
20
+
21
+ # theca-sdk-python
22
+
23
+ Run your own private CA at [devnull.cn](https://devnull.cn/pca): the service
24
+ signs a per-account root CA and SAN certificates, and this package writes the
25
+ PEM files to `~/.devnull/certs/`.
26
+
27
+ Requires `theid>=2` (theid 2.0 credentials; the service only accepts EdDSA
28
+ access tokens).
29
+
30
+ ## Usage
31
+
32
+ ```bash
33
+ # Credentials come from ~/.devnull/credentials (shared with devnull-cli) or env
34
+ export THEID_ACCESS_KEY=DK...
35
+ export THEID_SECRET_KEY=...
36
+
37
+ python3 - <<'EOF'
38
+ from theca import create_cert
39
+ print(create_cert())
40
+ EOF
41
+
42
+ ls -lt ~/.devnull/certs/
43
+ # key.pem crt.pem fullchain.pem ca.pem system_id subject_alternative_names properties
44
+ ```
45
+
46
+ `create_cert()` creates the account's root CA on first use, then issues a
47
+ certificate for the host's `system_id` plus its `private`/`public` thedns
48
+ names, and writes the chain next to it. The returned `ca_url`
49
+ (`https://devnull.cn/getca/<orgid>`) downloads the CA certificate.
50
+
51
+ Point at another environment with `DEVNULL_PCA_URL`
52
+ (default `https://devnull.cn/pca`; the 3.0.1 name `DEVNULL_THECA_URL` is still read). The identity service is resolved by
53
+ `theid` (`DEVNULL_BASE_URL` / `THEID_ISSUER`).
54
+
55
+ ## What the service stores
56
+
57
+ Per account: one RSA-4096 root CA (10 years) and up to 11 RSA-2048
58
+ certificates (1 year, SANs from the requested names). All material is stored
59
+ in Postgres as base64 PEM; `create_cert()` is idempotent per common name.
@@ -2,7 +2,6 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  theca/__init__.py
5
- theca/_auth.py
6
5
  theca/_utils.py
7
6
  theca.egg-info/PKG-INFO
8
7
  theca.egg-info/SOURCES.txt
@@ -1,2 +1,2 @@
1
1
  requests~=2.31.0
2
- theid
2
+ theid>=2
theca-2.0.3/PKG-INFO DELETED
@@ -1,46 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: theca
3
- Version: 2.0.3
4
- Summary: Python library to run your own private CA.
5
- Home-page: https://devnull.cn
6
- Author: Xizhen Du
7
- Author-email: xizhendu@gmail.com
8
- Description-Content-Type: text/markdown
9
- License-File: LICENSE
10
- Requires-Dist: requests~=2.31.0
11
- Requires-Dist: theid
12
-
13
- # theca-sdk-python
14
-
15
-
16
-
17
- ### Usage 1: Set environment variables
18
- ```bash
19
- export DEVNULL_EMAIL="_your_registered_email"
20
- export DEVNULL_ACCESS_KEY="_your_access_key_"
21
- export DEVNULL_SECRET_KEY="_your_access_key_"
22
-
23
- python3 -c 'from theca import create_cert; create_cert()'
24
- ls -lt $HOME/.devnull/certs/
25
- ```
26
-
27
- ### Usage 2: Serve a credential file
28
- ```bash
29
- cat ~/.devnull/credentials
30
- [default]
31
- email = ca-by-devnull@outlook.com
32
- accesskey = _your_access_key_
33
- secretkey = _your_secret_key_
34
-
35
- python3 -c 'from theca import create_cert; create_cert()'
36
- ls -lt $HOME/.devnull/certs/
37
- ```
38
-
39
- ## Trust your private CA -- todo
40
- ```bash
41
- theca_add_ca --orgid 0c74e79c1014
42
- theca_add_ca --email ca-by-devnull@outlook.com
43
- ```
44
-
45
-
46
-
theca-2.0.3/README.md DELETED
@@ -1,34 +0,0 @@
1
- # theca-sdk-python
2
-
3
-
4
-
5
- ### Usage 1: Set environment variables
6
- ```bash
7
- export DEVNULL_EMAIL="_your_registered_email"
8
- export DEVNULL_ACCESS_KEY="_your_access_key_"
9
- export DEVNULL_SECRET_KEY="_your_access_key_"
10
-
11
- python3 -c 'from theca import create_cert; create_cert()'
12
- ls -lt $HOME/.devnull/certs/
13
- ```
14
-
15
- ### Usage 2: Serve a credential file
16
- ```bash
17
- cat ~/.devnull/credentials
18
- [default]
19
- email = ca-by-devnull@outlook.com
20
- accesskey = _your_access_key_
21
- secretkey = _your_secret_key_
22
-
23
- python3 -c 'from theca import create_cert; create_cert()'
24
- ls -lt $HOME/.devnull/certs/
25
- ```
26
-
27
- ## Trust your private CA -- todo
28
- ```bash
29
- theca_add_ca --orgid 0c74e79c1014
30
- theca_add_ca --email ca-by-devnull@outlook.com
31
- ```
32
-
33
-
34
-
@@ -1,54 +0,0 @@
1
- import pathlib
2
- import configparser
3
- import hashlib
4
- import requests
5
- import json
6
- import os
7
-
8
- def _credentials():
9
- try:
10
- if 'DEVNULL_ACCESS_KEY' and 'DEVNULL_SECRET_KEY' and 'DEVNULL_EMAIL' in os.environ:
11
- accesskey = os.environ['DEVNULL_ACCESS_KEY']
12
- secretkey = os.environ['DEVNULL_SECRET_KEY']
13
- email = os.environ['DEVNULL_EMAIL']
14
- else:
15
- config_dir = pathlib.Path.home() / '.devnull'
16
- pathlib.Path(config_dir).mkdir(parents=True, exist_ok=True)
17
- _c = config_dir / 'credentials'
18
- with _c.open('r') as f:
19
- config = configparser.ConfigParser()
20
- config.read_file(f)
21
- accesskey = config['default']['accesskey']
22
- secretkey = config['default']['secretkey']
23
- email = config['default']['email']
24
- except:
25
- accesskey = 'j6QWLQhtUoNkTZLmzPtjHzm9'
26
- secretkey = '89GNI4UGgBxLdgELkvYKB6EP'
27
- email = 'ca-by-devnull@outlook.com'
28
- return accesskey, secretkey, email
29
-
30
-
31
- def _token(email, access_key, secret_key):
32
- hashed_access_key = hashlib.sha256(access_key.encode()).hexdigest()
33
- hashed_secret_key = hashlib.sha256(secret_key.encode()).hexdigest()
34
- hashed_email = hashlib.md5(email.encode()).hexdigest()
35
- _plain = hashed_access_key + hashed_secret_key
36
- _password = hashlib.sha256(_plain.encode()).hexdigest()
37
- # print(_password)
38
- data = json.dumps({
39
- 'email': email,
40
- 'checksum': hashed_email,
41
- 'accesskey': access_key,
42
- 'password': _password,
43
- 'resource_type': 'token'
44
- })
45
- headers = {'Content-Type': 'application/json'}
46
- _= requests.post('https://devnull.cn/identity', data=data, headers=headers).json()
47
- token_string = 'Bearer ' + _['token']
48
- return token_string
49
-
50
- def _request_headers(token=None):
51
- return {
52
- 'Authorization': token,
53
- 'Content-Type': 'application/json'
54
- }
@@ -1,46 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: theca
3
- Version: 2.0.3
4
- Summary: Python library to run your own private CA.
5
- Home-page: https://devnull.cn
6
- Author: Xizhen Du
7
- Author-email: xizhendu@gmail.com
8
- Description-Content-Type: text/markdown
9
- License-File: LICENSE
10
- Requires-Dist: requests~=2.31.0
11
- Requires-Dist: theid
12
-
13
- # theca-sdk-python
14
-
15
-
16
-
17
- ### Usage 1: Set environment variables
18
- ```bash
19
- export DEVNULL_EMAIL="_your_registered_email"
20
- export DEVNULL_ACCESS_KEY="_your_access_key_"
21
- export DEVNULL_SECRET_KEY="_your_access_key_"
22
-
23
- python3 -c 'from theca import create_cert; create_cert()'
24
- ls -lt $HOME/.devnull/certs/
25
- ```
26
-
27
- ### Usage 2: Serve a credential file
28
- ```bash
29
- cat ~/.devnull/credentials
30
- [default]
31
- email = ca-by-devnull@outlook.com
32
- accesskey = _your_access_key_
33
- secretkey = _your_secret_key_
34
-
35
- python3 -c 'from theca import create_cert; create_cert()'
36
- ls -lt $HOME/.devnull/certs/
37
- ```
38
-
39
- ## Trust your private CA -- todo
40
- ```bash
41
- theca_add_ca --orgid 0c74e79c1014
42
- theca_add_ca --email ca-by-devnull@outlook.com
43
- ```
44
-
45
-
46
-
File without changes
File without changes