Skip to content

Commit

Permalink
Add x509-viewec (#38)
Browse files Browse the repository at this point in the history
`x509-viewec` displays elliptic curve parameters with `openssl ecparam`
  • Loading branch information
jobbflykt authored Nov 12, 2024
1 parent c3874db commit 4031971
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# x509-mode [![MELPA](https://melpa.org/packages/x509-mode-badge.svg)](https://melpa.org/#/x509-mode)

Major mode for viewing certificates, CRLs, keys, DH-parameters and ASN.1 using [OpenSSL](https://github.com/openssl/openssl).
Major mode for viewing certificates, CRLs, keys, DH-parameters, EC-Parameters and ASN.1 using [OpenSSL](https://github.com/openssl/openssl).

## Usage

Expand All @@ -17,6 +17,7 @@ To view certificates, CRLs, private and public keys Diffie-Hellman parameters, c
M-x x509-viewkey
M-x x509-viewpublickey
M-x x509-viewdh
M-x x509-viewec
M-x x509-viewreq
M-x x509-viewpkcs7
M-x x509-viewasn1
Expand Down Expand Up @@ -108,6 +109,9 @@ x509-mode works with, for example, OpenSSL that comes with Git for Windows.

![CRL](https://github.com/jobbflykt/x509-mode/raw/master/screenshots/screenshot-dhparams.png)

**EC-params**

![CRL](https://github.com/jobbflykt/x509-mode/raw/master/screenshots/screenshot-ecparams.png)

**ASN.1**

Expand Down
7 changes: 7 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ Generator (hybrid):
serial:
DH Parameters:

# encode_key2text.c
EC-Parameters:

# eck_prn.c ECPKParameters_print
A:
B:

# openssl/crypto/x509v3/v3_bcons.c
# X509V3_add_value_bool
pathlen
Expand Down
5 changes: 4 additions & 1 deletion notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Remains:
length as being zero since we can't (easily) know.
- [X] Add unit tests.
- [X] Separate faces for header and value.
* TODO Use compat
* DONE Use compat
How to use compat
https://www.reddit.com/r/emacs/comments/10iep0o/compat_29130/

Expand All @@ -372,3 +372,6 @@ https://www.reddit.com/r/emacs/comments/10iep0o/compat_29130/

(require 'compat)
#+end_src
* DONE EC-Parameters
- [X] Add keywords and find out where in openssl they are defined.
- [X] Add ert tests.
Binary file added screenshots/screenshot-ecparams.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions testfiles/ec-params.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-----BEGIN EC PARAMETERS-----
MIIB5gIBATBMBgcqhkjOPQEBAkEA2FXXx8/oQxG4Uhuic2YH2xXZqYDgYUyH/ogp
HnuCWS9grRn1v8AWCpEdwrloaH63oYQN/sKQAVfRf8k1J7nKpzCByARAAgK0Agsl
YcJvokRDUCnNloLbfHEya0rbeZNf6DPwc9T4mcU7/H1Hs9hjxC9bE/N2njtLpaR2
bykyE9Or5GOkngRAMyIQgOcnU06PyEY9CZG3b+i0hEOp9bHoVJnm6uhjwY/97aH8
mG/Pkr4N2B8ZzkaOmz5A4Ujejx4WR39TRlS0ywNCAAHG1Hq3nS8FBhpmZJGvWHmv
Bjj0RCCU9MtcFZU5Ncfralhq3kjrzbTVSmVU9m/QEHni+qDIawyMX4ktm7mcpJo8
BIGBBEJk6lNnM17uHfxPPFe6975BDgLoQW7cNbuVxF1ozxkuB8g75+iqTi+GerH9
RbsFraw2RPbwPH8fQzTLniHXHkEBVvoisBzZqI/Y4DzmDhQexeMcEk0QUw+NxA+k
wLYyb+gB9VH7G0RqnZuraqk5Y0+1wNbFiu3w0lBOSpdEGrJJAkEA2FXXx8/oQxG4
Uhuic2YH2xXZqYDgYUyH/ogpHnuCWS8oKmc+nL5CRANkM1N1byv/8WsUio+aJDqR
MY2SccEWYQIBAQ==
-----END EC PARAMETERS-----
6 changes: 6 additions & 0 deletions x509-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ When `x509-warn-near-expire-days' is nil."
(should (equal 'x509--viewcrl-history (x509--get-x509-history "crl")))
(should (equal 'x509--viewpkcs7-history (x509--get-x509-history "pkcs7")))
(should (equal 'x509--viewdh-history (x509--get-x509-history "dhparam")))
(should (equal 'x509--viewec-history (x509--get-x509-history "ecparam")))
(should (equal 'x509--viewkey-history (x509--get-x509-history "pkey")))
(should
(equal 'x509--viewpublickey-history (x509--get-x509-history "pkey -pubin")))
Expand Down Expand Up @@ -446,6 +447,11 @@ Repeat with `x509-dwim' which should produce the same result."
)
'x509-viewdh 'x509-mode "DH Parameters: (4096 bit)"))

(ert-deftest x509-viewec ()
"View elliptic curve parameters."
(view-test-helper
'("ec-params.pem") 'x509-viewec 'x509-mode "EC-Parameters: (512 bit)"))

(ert-deftest x509-viewkey ()
"View plaintext private key."
(view-test-helper
Expand Down
21 changes: 21 additions & 0 deletions x509-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ Example:
:type 'string
:group 'x509)

(defcustom x509-ecparam-default-arg "ecparam -text -noout"
"Default arguments for \"openssl ecparam\" command."
:type 'string
:group 'x509)

(defcustom x509-pkey-default-arg "pkey -text -noout"
"Default arguments for \"openssl pkey\" command."
:type 'string
Expand Down Expand Up @@ -722,6 +727,7 @@ Switch to resulting buffer and return it."
("crl" 'x509--viewcrl-history)
("pkcs7" 'x509--viewpkcs7-history)
("dhparam" 'x509--viewdh-history)
("ecparam" 'x509--viewec-history)
("pkey" (if (string-match-p "-pubin" args)
'x509--viewpublickey-history
'x509--viewkey-history))
Expand Down Expand Up @@ -818,6 +824,18 @@ With \\[universal-argument] prefix, you can edit the command arguments."
(x509--generic-view
x509-dhparam-default-arg 'x509--viewdh-history 'x509-mode))

;; ---------------------------------------------------------------------------
(defvar x509--viewec-history nil
"History list for `x509-viewec'.")
;;;###autoload
(defun x509-viewec ()
"Parse current buffer as a EC-parameter file.
With \\[universal-argument] prefix, you can edit the command arguments."
(interactive)
(x509--generic-view
x509-ecparam-default-arg 'x509--viewec-history 'x509-mode))

;; ---------------------------------------------------------------------------
(defvar x509--viewkey-history nil
"History list for `x509-viewkey'.")
Expand Down Expand Up @@ -994,6 +1012,7 @@ different openssl commands until one succeeds. Call
(call-interactively #'x509-viewcert))
("CERTIFICATE REQUEST" (call-interactively #'x509-viewreq))
("DH PARAMETERS" (call-interactively #'x509-viewdh))
("DC PARAMETERS" (call-interactively #'x509-viewec))
("PKCS7" (call-interactively #'x509-viewpkcs7))
((or "ENCRYPTED PRIVATE KEY" "PRIVATE KEY" "RSA PRIVATE KEY")
(call-interactively #'x509-viewkey))
Expand All @@ -1013,6 +1032,8 @@ different openssl commands until one succeeds. Call
(call-interactively #'x509-viewreq))
((x509--dwim-tester x509-dhparam-default-arg)
(call-interactively #'x509-viewdh))
((x509--dwim-tester x509-ecparam-default-arg)
(call-interactively #'x509-viewec))
((x509--dwim-tester x509-pkcs7-default-arg)
(call-interactively #'x509-viewpkcs7))
(t
Expand Down

0 comments on commit 4031971

Please sign in to comment.