Plan 9 from Bell Labs’s /usr/web/sources/contrib/rog/infauth/unpacked/appl/authsrc/authcvt.b

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


implement Authcvt;

include "sys.m";
	sys: Sys;
include "draw.m";
include "keyring.m";
	keyring: Keyring;
	IPint: import keyring;
	SK, PK, Certificate, DigestState: import Keyring;
include "sexprs.m";
	sexprs: Sexprs;
	Sexp: import sexprs;

Authcvt: module {
	init: fn(nil: ref Draw->Context, argv: list of string);
};

init(nil: ref Draw->Context, argv: list of string)
{
	sys = load Sys Sys->PATH;
	sexprs = load Sexprs Sexprs->PATH;
	sexprs->init();
	keyring = load Keyring Keyring->PATH;

	if(len argv != 2)
		error("usage: authcvt keyfile");

	ai := keyring->readauthinfo(hd tl argv);
	if(ai == nil)
		error(sys->sprint("cannot read %s: %r", hd tl argv));
	for(r := "server" :: "client" :: nil; r != nil; r = tl r){
		if(sys->print("key proto=infauth role=%s name=%s %q\n", hd r, ai.mypk.owner, "!authinfo="+authinfotostr(ai)) == -1)
			error(sys->sprint("add key failed: %r"));
	}
}

error(e: string)
{
	sys->fprint(sys->fildes(2), "authcvt: %s\n", e);
	raise "fail:error";
}

authinfotostr(ai: ref Keyring->Authinfo): string
{
	return (ref Sexp.List(
		ss(keyring->pktostr(ai.spk)) ::
		ss(keyring->certtostr(ai.cert)) ::
		ss(keyring->sktostr(ai.mysk)) ::
		sd(ai.alpha.iptobytes()) ::
		sd(ai.p.iptobytes()) ::
		nil
	)).b64text();
}

ss(s: string): ref Sexp.String
{
	return ref Sexp.String(s, nil);
}

sd(d: array of byte): ref Sexp.Binary
{
	return ref Sexp.Binary(d, nil);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].