Merge branch 'master' of gitlab.com:MasterPassword/MasterPassword
This commit is contained in:
		
							
								
								
									
										1
									
								
								platform-independent/c/cli/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								platform-independent/c/cli/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -14,3 +14,4 @@ CMakeCache.txt
 | 
			
		||||
CMakeFiles
 | 
			
		||||
Makefile
 | 
			
		||||
cmake_install.cmake
 | 
			
		||||
install_manifest.txt
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
### CMAKE
 | 
			
		||||
project( mpw C )
 | 
			
		||||
project( masterpassword-cli C )
 | 
			
		||||
cmake_minimum_required( VERSION 3.0.2 )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -39,8 +39,8 @@ endif()
 | 
			
		||||
### DEPENDENCIES
 | 
			
		||||
function( use_mpw_sodium t r )
 | 
			
		||||
    if( USE_SODIUM )
 | 
			
		||||
        target_link_libraries(  "${t}" sodium )
 | 
			
		||||
        target_compile_definitions( "${t}" PUBLIC -DMPW_SODIUM=1 )
 | 
			
		||||
        target_link_libraries(  "${t}" PRIVATE sodium )
 | 
			
		||||
        target_compile_definitions( "${t}" PRIVATE -DMPW_SODIUM=1 )
 | 
			
		||||
        message( STATUS         "${t}: USE_SODIUM is enabled." )
 | 
			
		||||
 | 
			
		||||
    elseif( r STREQUAL "required" )
 | 
			
		||||
@@ -56,9 +56,9 @@ function( use_mpw_color t )
 | 
			
		||||
    find_package( Curses )
 | 
			
		||||
    if( USE_COLOR )
 | 
			
		||||
        if ( CURSES_FOUND )
 | 
			
		||||
            target_include_directories( "${t}" PUBLIC ${CURSES_INCLUDE_DIR} )
 | 
			
		||||
            target_link_libraries( "${t}" ${CURSES_LIBRARIES} )
 | 
			
		||||
            target_compile_definitions( "${t}" PUBLIC -DMPW_COLOR=1 ${CURSES_DEFINITIONS} )
 | 
			
		||||
            target_include_directories( "${t}" PRIVATE ${CURSES_INCLUDE_DIR} )
 | 
			
		||||
            target_link_libraries( "${t}" PRIVATE ${CURSES_LIBRARIES} )
 | 
			
		||||
            target_compile_definitions( "${t}" PRIVATE -DMPW_COLOR=1 ${CURSES_DEFINITIONS} )
 | 
			
		||||
            message( STATUS     "${t}: USE_COLOR is enabled." )
 | 
			
		||||
 | 
			
		||||
        elseif( r STREQUAL "required" )
 | 
			
		||||
@@ -80,8 +80,8 @@ endfunction()
 | 
			
		||||
 | 
			
		||||
function( use_mpw_json t )
 | 
			
		||||
    if( USE_JSON )
 | 
			
		||||
        target_link_libraries(  "${t}" json-c )
 | 
			
		||||
        target_compile_definitions( "${t}" PUBLIC -DMPW_JSON=1 )
 | 
			
		||||
        target_link_libraries(  "${t}" PRIVATE json-c )
 | 
			
		||||
        target_compile_definitions( "${t}" PRIVATE -DMPW_JSON=1 )
 | 
			
		||||
        message( STATUS         "${t}: USE_JSON is enabled." )
 | 
			
		||||
 | 
			
		||||
    elseif( r STREQUAL "required" )
 | 
			
		||||
@@ -97,9 +97,9 @@ function( use_mpw_xml t r )
 | 
			
		||||
    find_package( LibXml2 )
 | 
			
		||||
    if( USE_XML )
 | 
			
		||||
        if ( LIBXML2_FOUND )
 | 
			
		||||
            target_include_directories( "${t}" PUBLIC ${LIBXML2_INCLUDE_DIR} )
 | 
			
		||||
            target_link_libraries( "${t}" ${LIBXML2_LIBRARIES} )
 | 
			
		||||
            target_compile_definitions( "${t}" PUBLIC -DMPW_XML=1 ${LIBXML2_DEFINITIONS} )
 | 
			
		||||
            target_include_directories( "${t}" PRIVATE ${LIBXML2_INCLUDE_DIR} )
 | 
			
		||||
            target_link_libraries( "${t}" PRIVATE ${LIBXML2_LIBRARIES} )
 | 
			
		||||
            target_compile_definitions( "${t}" PRIVATE -DMPW_XML=1 ${LIBXML2_DEFINITIONS} )
 | 
			
		||||
            message( STATUS     "${t}: USE_XML is enabled." )
 | 
			
		||||
 | 
			
		||||
        elseif( r STREQUAL "required" )
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ artifacts {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
library {
 | 
			
		||||
    baseName.set( "mpw" )
 | 
			
		||||
    linkage.set( [ Linkage.SHARED ] )
 | 
			
		||||
 | 
			
		||||
    // Reconfigure the toolchain from C++ to C.
 | 
			
		||||
 
 | 
			
		||||
@@ -6,10 +6,21 @@
 | 
			
		||||
 | 
			
		||||
// TODO: We may need to zero the jbytes safely.
 | 
			
		||||
 | 
			
		||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
 | 
			
		||||
    JNIEnv* env;
 | 
			
		||||
    if ((*vm)->GetEnv( vm, (void **)&env, JNI_VERSION_1_6 ) != JNI_OK)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    return JNI_VERSION_1_6;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* native int _masterKey(final String fullName, final byte[] masterPassword, final Version version) */
 | 
			
		||||
JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1masterKey(JNIEnv *env, jobject obj,
 | 
			
		||||
        jstring fullName, jbyteArray masterPassword, jint algorithmVersion) {
 | 
			
		||||
 | 
			
		||||
    if (!fullName || !masterPassword)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    const char *fullNameString = (*env)->GetStringUTFChars( env, fullName, NULL );
 | 
			
		||||
    jbyte *masterPasswordString = (*env)->GetByteArrayElements( env, masterPassword, NULL );
 | 
			
		||||
 | 
			
		||||
@@ -32,6 +43,9 @@ JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__
 | 
			
		||||
JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1siteKey(JNIEnv *env, jobject obj,
 | 
			
		||||
        jbyteArray masterKey, jstring siteName, jlong siteCounter, jint keyPurpose, jstring keyContext, jint algorithmVersion) {
 | 
			
		||||
 | 
			
		||||
    if (!masterKey || !siteName)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    jbyte *masterKeyBytes = (*env)->GetByteArrayElements( env, masterKey, NULL );
 | 
			
		||||
    const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL );
 | 
			
		||||
    const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL;
 | 
			
		||||
@@ -40,7 +54,8 @@ JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__
 | 
			
		||||
            (MPKeyPurpose)keyPurpose, keyContextString, (MPAlgorithmVersion)algorithmVersion );
 | 
			
		||||
    (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, siteName, siteNameString );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, keyContext, keyContextString );
 | 
			
		||||
    if (keyContext)
 | 
			
		||||
        (*env)->ReleaseStringUTFChars( env, keyContext, keyContextString );
 | 
			
		||||
 | 
			
		||||
    if (!siteKeyBytes)
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -59,6 +74,9 @@ JNIEXPORT jstring JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1si
 | 
			
		||||
        jbyteArray masterKey, jbyteArray siteKey, jstring siteName, jlong siteCounter, jint keyPurpose, jstring keyContext,
 | 
			
		||||
        jint resultType, jstring resultParam, jint algorithmVersion) {
 | 
			
		||||
 | 
			
		||||
    if (!masterKey || !siteKey || !siteName)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    jbyte *masterKeyBytes = (*env)->GetByteArrayElements( env, masterKey, NULL );
 | 
			
		||||
    jbyte *siteKeyBytes = (*env)->GetByteArrayElements( env, siteKey, NULL );
 | 
			
		||||
    const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL );
 | 
			
		||||
@@ -70,8 +88,10 @@ JNIEXPORT jstring JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1si
 | 
			
		||||
    (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT );
 | 
			
		||||
    (*env)->ReleaseByteArrayElements( env, siteKey, siteKeyBytes, JNI_ABORT );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, siteName, siteNameString );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, keyContext, keyContextString );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, resultParam, resultParamString );
 | 
			
		||||
    if (keyContext)
 | 
			
		||||
        (*env)->ReleaseStringUTFChars( env, keyContext, keyContextString );
 | 
			
		||||
    if (resultParam)
 | 
			
		||||
        (*env)->ReleaseStringUTFChars( env, resultParam, resultParamString );
 | 
			
		||||
 | 
			
		||||
    if (!siteResultString)
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -89,6 +109,9 @@ JNIEXPORT jstring JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1si
 | 
			
		||||
        jbyteArray masterKey, jbyteArray siteKey, jstring siteName, jlong siteCounter, jint keyPurpose, jstring keyContext,
 | 
			
		||||
        jint resultType, jstring resultParam, jint algorithmVersion) {
 | 
			
		||||
 | 
			
		||||
    if (!masterKey || !siteKey || !siteName || !resultParam)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    jbyte *masterKeyBytes = (*env)->GetByteArrayElements( env, masterKey, NULL );
 | 
			
		||||
    jbyte *siteKeyBytes = (*env)->GetByteArrayElements( env, siteKey, NULL );
 | 
			
		||||
    const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL );
 | 
			
		||||
@@ -100,8 +123,10 @@ JNIEXPORT jstring JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1si
 | 
			
		||||
    (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT );
 | 
			
		||||
    (*env)->ReleaseByteArrayElements( env, siteKey, siteKeyBytes, JNI_ABORT );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, siteName, siteNameString );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, keyContext, keyContextString );
 | 
			
		||||
    (*env)->ReleaseStringUTFChars( env, resultParam, resultParamString );
 | 
			
		||||
    if (keyContextString)
 | 
			
		||||
        (*env)->ReleaseStringUTFChars( env, keyContext, keyContextString );
 | 
			
		||||
    if (resultParam)
 | 
			
		||||
        (*env)->ReleaseStringUTFChars( env, resultParam, resultParamString );
 | 
			
		||||
 | 
			
		||||
    if (!siteStateString)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 
 | 
			
		||||
@@ -95,7 +95,7 @@ bool mpw_get_json_boolean(
 | 
			
		||||
    if (!json_value)
 | 
			
		||||
        return defaultValue;
 | 
			
		||||
 | 
			
		||||
    return json_object_get_boolean( json_value ) == TRUE;
 | 
			
		||||
    return json_object_get_boolean( json_value ) == true;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,7 @@ public class MPAlgorithmV0 extends MPAlgorithm {
 | 
			
		||||
    protected static final int    AES_BLOCKSIZE      = 128 /* bit */;
 | 
			
		||||
 | 
			
		||||
    static {
 | 
			
		||||
        Native.load( MPAlgorithmV0.class, "masterpassword-core" );
 | 
			
		||||
        Native.load( MPAlgorithmV0.class, "mpw" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public final Version version = MPAlgorithm.Version.V0;
 | 
			
		||||
 
 | 
			
		||||
@@ -40,8 +40,16 @@ public final class Native {
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings({ "HardcodedFileSeparator", "LoadLibraryWithNonConstantString" })
 | 
			
		||||
    public static void load(final Class<?> context, final String name) {
 | 
			
		||||
 | 
			
		||||
        // Try to load the library using the native system.
 | 
			
		||||
        try {
 | 
			
		||||
            System.loadLibrary( name );
 | 
			
		||||
            return;
 | 
			
		||||
        } catch (@SuppressWarnings("ErrorNotRethrown") final UnsatisfiedLinkError ignored) {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Try to find and open a stream to the packaged library resource.
 | 
			
		||||
        try {
 | 
			
		||||
            // Find and open a stream to the packaged library resource.
 | 
			
		||||
            String      library          = System.mapLibraryName( name );
 | 
			
		||||
            int         libraryDot       = library.lastIndexOf( EXTENSION_SEPARATOR );
 | 
			
		||||
            String      libraryName      = (libraryDot > 0)? library.substring( 0, libraryDot ): library;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user