namespace Net.Pkcs11Interop.Tests
{
public static class Settings
{
#region Properties that almost always need to be configured before the tests are executed
public static Pkcs11InteropFactories Factories = new Pkcs11InteropFactories();
public static string Pkcs11LibraryPath = GetPkcs11MockLibraryPath();
public static string TokenSerial = null;
public static string TokenLabel = null;
public static string SecurityOfficerPin = @"11111111";
public static string NormalUserPin = @"11111111";
public static string ApplicationName = @"Pkcs11Interop";
#endregion
#region Properties that are set automatically in class constructor
public static LLA40.CK_C_INITIALIZE_ARGS InitArgs40 = null;
public static LLA41.CK_C_INITIALIZE_ARGS InitArgs41 = null;
public static LLA80.CK_C_INITIALIZE_ARGS InitArgs80 = null;
public static LLA81.CK_C_INITIALIZE_ARGS InitArgs81 = null;
public static byte[] SecurityOfficerPinArray = null;
public static byte[] NormalUserPinArray = null;
public static byte[] ApplicationNameArray = null;
public static string PrivateKeyUri = null;
#endregion
static Settings()
{
{
InitArgs40 = new LLA40.CK_C_INITIALIZE_ARGS();
InitArgs40.Flags = CKF.CKF_OS_LOCKING_OK;
InitArgs41 = new LLA41.CK_C_INITIALIZE_ARGS();
InitArgs41.Flags = CKF.CKF_OS_LOCKING_OK;
InitArgs80 = new LLA80.CK_C_INITIALIZE_ARGS();
InitArgs80.Flags = CKF.CKF_OS_LOCKING_OK;
InitArgs81 = new LLA81.CK_C_INITIALIZE_ARGS();
InitArgs81.Flags = CKF.CKF_OS_LOCKING_OK;
}
SecurityOfficerPinArray = ConvertUtils.Utf8StringToBytes(SecurityOfficerPin);
NormalUserPinArray = ConvertUtils.Utf8StringToBytes(NormalUserPin);
ApplicationNameArray = ConvertUtils.Utf8StringToBytes(ApplicationName);
Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
pkcs11UriBuilder.ModulePath = Pkcs11LibraryPath;
pkcs11UriBuilder.Serial = TokenSerial;
pkcs11UriBuilder.Token = TokenLabel;
pkcs11UriBuilder.PinValue = NormalUserPin;
pkcs11UriBuilder.Type =
CKO.CKO_PRIVATE_KEY;
pkcs11UriBuilder.Object = ApplicationName;
PrivateKeyUri = pkcs11UriBuilder.ToString();
}
private static string GetPkcs11MockLibraryPath()
{
#if __ANDROID__
return @"libpkcs11-mock.so";
#elif __IOS__
return string.Empty;
#else
string path = typeof(Settings).Assembly.CodeBase;
path = new Uri(path).LocalPath;
path = Path.GetDirectoryName(path);
path = Path.Combine(path, "pkcs11-mock");
if (Platform.IsWindows)
{
path = Path.Combine(path, "windows");
path = Path.Combine(path, "pkcs11-mock-" + (Platform.Uses32BitRuntime ? "x86" : "x64") + ".dll");
}
else if (Platform.IsLinux)
{
path = Path.Combine(path, "linux");
path = Path.Combine(path, "pkcs11-mock-" + (Platform.Uses32BitRuntime ? "x86" : "x64") + ".so");
}
else if (Platform.IsMacOsX)
{
path = Path.Combine(path, "osx");
path = Path.Combine(path, "pkcs11-mock-" + (Platform.Uses32BitRuntime ? "x86" : "x64") + ".dylib");
}
return path;
#endif
}
}
}