Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2020-02-17 22:53:19 +0300
committerSimon Tatham <anakin@pobox.com>2020-02-22 21:42:13 +0300
commitc18e5dc8fbfd33d3544fee8977fc590339416b7e (patch)
tree8c437d0412fe5a8548d1f6c7fe6d537fe6ecfac5 /sshpubk.c
parent96f1fb9456255c5ce982a168b6b35ae448dfbbf4 (diff)
cmdgen: add a --dump option.
Also spelled '-O text', this takes a public or private key as input, and produces on standard output a dump of all the actual numbers involved in the key: the exponent and modulus for RSA, the p,q,g,y parameters for DSA, the affine x and y coordinates of the public elliptic curve point for ECC keys, and all the extra bits and pieces in the private keys too. Partly I expect this to be useful to me for debugging: I've had to paste key files a few too many times through base64 decoders and hex dump tools, then manually decode SSH marshalling and paste the result into the Python REPL to get an integer object. Now I should be able to get _straight_ to text I can paste into Python. But also, it's a way that other applications can use the key generator: if you need to generate, say, an RSA key in some format I don't support (I've recently heard of an XML-based one, for example), then you can run 'puttygen -t rsa --dump' and have it print the elements of a freshly generated keypair on standard output, and then all you have to do is understand the output format.
Diffstat (limited to 'sshpubk.c')
-rw-r--r--sshpubk.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/sshpubk.c b/sshpubk.c
index ac995b69..cbf42c93 100644
--- a/sshpubk.c
+++ b/sshpubk.c
@@ -1730,3 +1730,47 @@ const char *key_type_to_str(int type)
unreachable("bad key type in key_type_to_str");
}
}
+
+key_components *key_components_new(void)
+{
+ key_components *kc = snew(key_components);
+ kc->ncomponents = 0;
+ kc->componentsize = 0;
+ kc->components = NULL;
+ return kc;
+}
+
+void key_components_add_text(key_components *kc,
+ const char *name, const char *value)
+{
+ sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
+ size_t n = kc->ncomponents++;
+ kc->components[n].name = dupstr(name);
+ kc->components[n].is_mp_int = false;
+ kc->components[n].text = dupstr(value);
+}
+
+void key_components_add_mp(key_components *kc,
+ const char *name, mp_int *value)
+{
+ sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
+ size_t n = kc->ncomponents++;
+ kc->components[n].name = dupstr(name);
+ kc->components[n].is_mp_int = true;
+ kc->components[n].mp = mp_copy(value);
+}
+
+void key_components_free(key_components *kc)
+{
+ for (size_t i = 0; i < kc->ncomponents; i++) {
+ sfree(kc->components[i].name);
+ if (kc->components[i].is_mp_int) {
+ mp_free(kc->components[i].mp);
+ } else {
+ smemclr(kc->components[i].text, strlen(kc->components[i].text));
+ sfree(kc->components[i].text);
+ }
+ }
+ sfree(kc->components);
+ sfree(kc);
+}