android: Add utility JNI function to validate proposal strings

This commit is contained in:
Tobias Brunner 2017-11-17 17:26:51 +01:00
parent 2307bffe56
commit 836a943804
2 changed files with 37 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 Tobias Brunner
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2014-2017 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -37,4 +37,13 @@ public class Utils
}
return new String(hex);
}
/**
* Validate the given proposal string
*
* @param ike true for IKE, false for ESP
* @param proposal proposal string
* @return true if valid
*/
public native static boolean isProposalValid(boolean ike, String proposal);
}

View File

@ -716,3 +716,29 @@ JNI_METHOD(CharonVpnService, initiate, void,
initiate(settings);
}
/**
* Utility function to verify proposal strings (static, so `this` is the class)
*/
JNI_METHOD_P(org_strongswan_android_utils, Utils, isProposalValid, jboolean,
jboolean ike, jstring proposal)
{
proposal_t *prop;
char *str;
bool valid;
dbg = dbg_android;
if (!library_init(NULL, "charon"))
{
library_deinit();
return FALSE;
}
str = androidjni_convert_jstring(env, proposal);
prop = proposal_create_from_string(ike ? PROTO_IKE : PROTO_ESP, str);
valid = prop != NULL;
DESTROY_IF(prop);
free(str);
library_deinit();
return valid;
}