PEM to vkey for MTC#1068
Merged
Merged
Conversation
AlCutter
force-pushed
the
pem_to_vkey
branch
4 times, most recently
from
July 21, 2026 15:16
9af51a0 to
d565a32
Compare
roger2hk
approved these changes
Jul 21, 2026
| oid/1.3.6.1.4.1.44363.47.1.11129.11.99.1+f3cdeae8+BqEI2mLl390er8KhOhcQIXsl5MiNpfCY+J8pPHfWOSIKph/S87zYk9IwoM/T+z5Q0VNMHw1AZrluGTb1VAEPzzZhdl/M6hPaMv5YCOvvhk68C9eeFzyibqH/WppChBwnfKx3/8DwtEtsb6tL8V0QYdOnEg9h8F+HxIusAaL5zBLpagaswSM1gSzmNf8EYeFqGC21CtdJqIzXtDVmn448mt7ojrxjekR4p9EoLDT74l6Hm2ONdbeBf4SexYfiXkb9JV3VcCzWzCzcol5MrNwpbYj1XfruEFlFdI5vffpS9Kj3ZkFgX5yEEVPv+WHIn9nqrL1BgqagIUFlYZdnrS8gHBiyD2Dtk4IZ6JfZ9xcFrvahoduGqprhbrCME/1sl3gRpw0rsg6xEXjko3EcgmOF0iGz+6df/pNDcc+6/3DvIp82DxSfLmTuwVN7lY/C4HT1LY7cIg7DzIZq4Qk8okkEuNv6mdnWZohIT+c8EuwFr8IG1kZqAA8b1VUwOCxMRr2YnxW0kUHPUeEADRk5SchNlg3L1mz9JfNFGOSGtFweCYztKuEZdxKgZWQ3iY+fF97KryfqkvYTfEj2KiIWKOT1xo/lcmFxrDe5+sMprle2wv3w2EOnkLk390zWr/NaLm2l8iic9L0t+SPLaWE17t9+t0TD34eaPrQOUEzYG8DAMMoOkFN+JbVGg7dEjZ1B/Lo85g9yHZaeAOb/4V0SwMQevCt9kbF9yEDCvWEf1wIrpYuKhYY+ErssEWdZzfhD3EDMnLAFPoLapL6AGZmxw0DmiOYJdhuexEEOKJuc9iEf4PCmnuVtxkOpiuVpZeoO8jjYFOj6WUpLo60/Pn8TTdKH4WJZyM3uOjGHV4oMNBSQzRb59IpbE/Xmifr4OR8+IIWM+3e1/VXcPpc/pgkQT5k/Ehgh3NFD1knfbtbq9rlOiszpz/sfEQ38rGeCRFU9hygDSIfkPV8q8Cqwm9IuERD1BNereYQBeF/TuS0+AgPJiGlnsJnw/KNrVkjnUMTQqeMbF9vx0VdN4v/RH+TGMgFKUfhl+fcUyjgni27/Wq9EqhrfZDsUFwaJmbJ021f2n7mGQ2m8F30GnnVjDtrNdZc6ssFB6BoN+YL7JM2IdyQDVy44PMSCqsTCLkquIR85GJPqfINPO+LWSbIKlcOObwLjxhcMzHguUm2eTews6YtdtnCSM9sjv2HVOJqiCbDB85559AhebR8m7cJCRDiw7JoocdDhBEc1lZIUOpq8VnivPwzBG92SXx5NbWUqYs2xkwFlf0vBMqD0hkTE/rUlWr48T7Fz9ITOVt8OJi9t9E+wYnwY7+CW6nzPFFscoyWC+WKxChnoOPNiZH7AUPa76rZkB2PFWBTKGkm220ZR66DGa16pxCUB2ZqCFvkRvEnq/sWM9jru3PBSTdBuLtZfWdt5st7HKcZkXHUV69opEchDtotairk1YCyBNnsvIOf5f/IOzKYCNEBuUAnfWxnQqSUjS89GZhBBoMOLs1nQNjTovy+Zgt5y6PVAsZjLvfRzYRFcwozCXQUrtlbpUbd17yL1XUbVg74shXywahFl6rSzrw2h8KG/5YpE5NLZIdko/uBtsXH0X+/wet4C/ygp/uA0Gz5550WXoM8IM2VbzuEA4xgjRMyWSP+B1SpCxG2xnR98shHtkYAnx2BNw9AQ44ygo2/W3Oq+IwCWvmle5YxiiYadblXy4R28oOIhpG4wHXMsCkaegT7O4Wf9jmcd5hrA2r4= | ||
| ``` | ||
|
|
||
| The `vkey` is the final (very long) line |
Contributor
There was a problem hiding this comment.
Suggested change
| The `vkey` is the final (very long) line | |
| The `vkey` is the final (very long) line. |
Comment on lines
+86
to
+89
| pub := crt.RawSubjectPublicKeyInfo[22:] | ||
| if l := len(pub); l != 1312 { | ||
| exit("Invalid public key length %d, expected 1312", l) | ||
| } |
Contributor
There was a problem hiding this comment.
This is some magical code. We can either add some code comment to explain what it does or use the "encoding/asn1" or "golang.org/x/crypto/cryptobyte" package.
Collaborator
Author
There was a problem hiding this comment.
I did say it was hacky :)
Ok, parsed out the algo and verified that it's ML-DSA-44.
Comment on lines
+63
to
+64
| der, _ := pem.Decode(c) | ||
| crt, err := x509.ParseCertificate(der.Bytes) |
Contributor
There was a problem hiding this comment.
If der from pem.Decode is nil, it will trigger a nil pointer dereference panic.
| } | ||
|
|
||
| func exit(m string, a ...any) { | ||
| fmt.Printf(m, a...) |
Contributor
There was a problem hiding this comment.
The string printed here will get into the shell prompt line. Add a \n?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains a quickly hacked-up tool for converting an X.509 PEM cert containing MTC CA IDs to a
vkeyfor use with the mtc mirror.Towards #945