+ return st;
+
+error_out:
+ if (st) rsapriv_dispose(st);
+ st=0;
+ goto out;
+}
+
+static bool_t postreadcheck_tryload(struct load_ctx *l, FILE *f)
+{
+ assert(!ferror(f));
+ if (feof(f)) { load_err(l,0,0,"eof mid-integer"); return False; }
+ return True;
+}
+
+bool_t rsa1_loadpriv(const struct sigscheme_info *algo,
+ struct buffer_if *privkeydata,
+ struct sigprivkey_if **sigpriv_r,
+ closure_t **closure_r,
+ struct log_if *log, struct cloc loc)
+{
+ FILE *f=0;
+ struct rsapriv *st=0;
+
+ f=fmemopen(privkeydata->start,privkeydata->size,"r");
+ if (!f) {
+ slilog(log,M_ERR,"failed to fmemopen private key file\n");
+ goto error_out;
+ }
+
+ struct load_ctx l[1];
+ l->what="rsa1priv load";
+ l->verror=verror_tryload;
+ l->postreadcheck=postreadcheck_tryload;
+ l->deprdict=0;
+ l->loc=loc;
+ l->u.tryload.log=log;
+
+ st=rsa_loadpriv_core(l,f,loc,False);
+ if (!st) goto error_out;
+ goto out;
+
+ error_out:
+ FREE(st);
+ out:
+ if (f) fclose(f);
+ if (!st) return False;
+ *sigpriv_r=&st->ops;
+ *closure_r=&st->cl;
+ return True;
+}
+
+static bool_t postreadcheck_apply(struct load_ctx *l, FILE *f)
+{
+ cfgfile_postreadcheck(l->loc,f);
+ return True;
+}
+
+static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
+ list_t *args)
+{
+ struct rsapriv *st;
+ item_t *i;
+ cstring_t filename;
+ FILE *f;
+ struct load_ctx l[1];
+
+ l->what="rsa-private";
+ l->verror=verror_cfgfatal;
+ l->postreadcheck=postreadcheck_apply;
+ l->deprdict=context;
+ l->loc=loc;
+
+ /* Argument is filename pointing to SSH1 private key file */
+ i=list_elem(args,0);
+ if (i) {
+ if (i->type!=t_string) {
+ cfgfatal(i->loc,"rsa-private","first argument must be a string\n");
+ }
+ filename=i->data.string;
+ } else {
+ filename=NULL; /* Make compiler happy */
+ cfgfatal(i->loc,"rsa-private","you must provide a filename\n");
+ }
+
+ f=fopen(filename,"rb");
+ if (!f) {
+ if (just_check_config) {
+ Message(M_WARNING,"rsa-private (%s:%d): cannot open keyfile "
+ "\"%s\" (%s); assuming it's valid while we check the "
+ "rest of the configuration\n",
+ loc.file,loc.line,filename,strerror(errno));
+ return list_new();
+ } else {
+ fatal_perror("rsa-private (%s:%d): cannot open file \"%s\"",
+ loc.file,loc.line,filename);
+ }
+ }
+
+ bool_t do_validity_check=True;
+ i=list_elem(args,1);
+ if (i && i->type==t_bool && i->data.bool==False) {
+ Message(M_INFO,"rsa-private (%s:%d): skipping RSA key validity "
+ "check\n",loc.file,loc.line);
+ do_validity_check=False;
+ }
+
+ st=rsa_loadpriv_core(l,f,loc,do_validity_check);
+ fclose(f);