diff options
author | Sven Gothel <[email protected]> | 2022-06-03 21:05:04 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-06-03 21:05:04 +0200 |
commit | 5446ccdf2e4729f4650013eed00b782effa3ef07 (patch) | |
tree | 72917d7f30cc081fd9930f08ed3800258b5a8882 /java/jni | |
parent | 44b63a6dc316bb0f4873360e6fce1e82509a005c (diff) |
Refine API and README doc (Use message, sender and receiver, emphasize on streaming); Restructure header and its processing, ..
Restructure header and its processing:
- avoid overflow at encryption by only encoding smaller chunks << 2048
- same done at decoding @ decryption, only producing a small recording buffer << 2048
- always close the header segment
- use proper names matching universal semantics
Diffstat (limited to 'java/jni')
-rw-r--r-- | java/jni/cipherpack/Cipherpack.cxx | 12 | ||||
-rw-r--r-- | java/jni/cipherpack/CipherpackHelper.cxx | 44 |
2 files changed, 20 insertions, 36 deletions
diff --git a/java/jni/cipherpack/Cipherpack.cxx b/java/jni/cipherpack/Cipherpack.cxx index 87c7684..9475d43 100644 --- a/java/jni/cipherpack/Cipherpack.cxx +++ b/java/jni/cipherpack/Cipherpack.cxx @@ -38,7 +38,7 @@ jobject Java_org_cipherpack_Cipherpack_encryptThenSignImpl1(JNIEnv *env, jclass jobject jccfg, jobject jenc_pub_keys, jstring jsign_sec_key_fname, jstring jpassphrase, jobject jsource_feed, - jstring jtarget_path, jstring jintention, + jstring jtarget_path, jstring jsubject, jstring jpayload_version, jstring jpayload_version_parent, jobject cpListener, jstring jdestination_fname) @@ -52,13 +52,13 @@ jobject Java_org_cipherpack_Cipherpack_encryptThenSignImpl1(JNIEnv *env, jclass std::string sign_sec_key_fname = jau::from_jstring_to_string(env, jsign_sec_key_fname); std::string passphrase = jau::from_jstring_to_string(env, jpassphrase); std::string target_path = jau::from_jstring_to_string(env, jtarget_path); - std::string intention = jau::from_jstring_to_string(env, jintention); + std::string subject = jau::from_jstring_to_string(env, jsubject); std::string payload_version = jau::from_jstring_to_string(env, jpayload_version); std::string payload_version_parent = jau::from_jstring_to_string(env, jpayload_version_parent); std::string destination_fname = nullptr != jdestination_fname ? jau::from_jstring_to_string(env, jdestination_fname) : ""; PackHeader ph = encryptThenSign(ccfg, enc_pub_keys, sign_sec_key_fname, passphrase, *refFeed, - target_path, intention, payload_version, payload_version_parent, + target_path, subject, payload_version, payload_version_parent, refListener.shared_ptr(), destination_fname); jobject jph = jcipherpack::to_jPackHeader(env, ph); @@ -74,7 +74,7 @@ jobject Java_org_cipherpack_Cipherpack_encryptThenSignImpl2(JNIEnv *env, jclass jobject jccfg, jobject jenc_pub_keys, jstring jsign_sec_key_fname, jstring jpassphrase, jstring jsource_loc, jlong jsource_timeout_ms, - jstring jtarget_path, jstring jintention, + jstring jtarget_path, jstring jsubject, jstring jpayload_version, jstring jpayload_version_parent, jobject cpListener, jstring jdestination_fname) @@ -95,13 +95,13 @@ jobject Java_org_cipherpack_Cipherpack_encryptThenSignImpl2(JNIEnv *env, jclass source = std::make_unique<jau::io::ByteInStream_File>(source_loc, true /* use_binary */); } std::string target_path = jau::from_jstring_to_string(env, jtarget_path); - std::string intention = jau::from_jstring_to_string(env, jintention); + std::string subject = jau::from_jstring_to_string(env, jsubject); std::string payload_version = jau::from_jstring_to_string(env, jpayload_version); std::string payload_version_parent = jau::from_jstring_to_string(env, jpayload_version_parent); std::string destination_fname = nullptr != jdestination_fname ? jau::from_jstring_to_string(env, jdestination_fname) : ""; PackHeader ph = encryptThenSign(ccfg, enc_pub_keys, sign_sec_key_fname, passphrase, *source, - target_path, intention, payload_version, payload_version_parent, + target_path, subject, payload_version, payload_version_parent, refListener.shared_ptr(), destination_fname); jobject jph = jcipherpack::to_jPackHeader(env, ph); diff --git a/java/jni/cipherpack/CipherpackHelper.cxx b/java/jni/cipherpack/CipherpackHelper.cxx index 6c258cc..1c04920 100644 --- a/java/jni/cipherpack/CipherpackHelper.cxx +++ b/java/jni/cipherpack/CipherpackHelper.cxx @@ -34,7 +34,7 @@ static const std::string _cryptoConfigClassName("org/cipherpack/CryptoConfig"); static const std::string _cryptoConfigClazzCtorArgs("(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V"); static const std::string _packHeaderClassName("org/cipherpack/PackHeader"); -static const std::string _packHeaderClazzCtorArgs("(Ljava/lang/String;JJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/cipherpack/CryptoConfig;Ljava/lang/String;Ljava/util/List;IZ)V"); +static const std::string _packHeaderClazzCtorArgs("(Ljava/lang/String;JJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/cipherpack/CryptoConfig;Ljava/lang/String;Ljava/util/List;IZ)V"); CryptoConfig jcipherpack::to_CryptoConfig(JNIEnv *env, jobject jccfg) { std::string pk_type_ = jau::getStringFieldValue(env, jccfg, "pk_type"); @@ -55,13 +55,6 @@ CryptoConfig jcipherpack::to_CryptoConfig(JNIEnv *env, jobject jccfg) { } jobject jcipherpack::to_jCryptoConfig(JNIEnv *env, const CryptoConfig& ccfg) { - // public CryptoConfig(final String pk_type_, - // final String pk_fingerprt_hash_algo_, - // final String pk_enc_padding_algo_, - // final String pk_enc_hash_algo_, - // final String pk_sign_algo_, - // final String sym_enc_algo_, - // final long sym_enc_nonce_bytes_) { jstring jpk_type = jau::from_string_to_jstring(env, ccfg.pk_type); jstring jpk_fingerprt_hash_algo = jau::from_string_to_jstring(env, ccfg.pk_fingerprt_hash_algo); jstring jpk_enc_padding_algo = jau::from_string_to_jstring(env, ccfg.pk_enc_padding_algo); @@ -91,27 +84,17 @@ jobject jcipherpack::to_jCryptoConfig(JNIEnv *env, const CryptoConfig& ccfg) { } jobject jcipherpack::to_jPackHeader(JNIEnv *env, const PackHeader& ph) { - // PackHeader(final String target_path_, - // final long content_size_, - // final long ts_creation_, - // final String intention_, - // final String pversion, final String pversion_parent, - // final CryptoConfig crypto_cfg_, - // final String host_key_fingerprint_, - // final List<String> term_keys_fingerprint_, - // final int term_key_fingerprint_used_idx_, - // final boolean valid_) { jstring jtarget_path = jau::from_string_to_jstring(env, ph.getTargetPath()); - jstring jintention = jau::from_string_to_jstring(env, ph.getIntention()); + jstring jsubject = jau::from_string_to_jstring(env, ph.getSubject()); jstring jpversion = jau::from_string_to_jstring(env, ph.getPayloadVersion()); jstring jpversion_parent = jau::from_string_to_jstring(env, ph.getPayloadVersionParent()); const CryptoConfig& ccfg = ph.getCryptoConfig(); jobject jccfg = to_jCryptoConfig(env, ccfg); - jstring jpk_host_key_fprint = jau::from_string_to_jstring(env, ph.getHostKeyFingerprint()); - const std::vector<std::string>& termKeysFingerprint = ph.getTermKeysFingerprint(); - jobject jtermKeysFingerprint = jau::convert_vector_string_to_jarraylist(env, termKeysFingerprint); + jstring jsender_fprint = jau::from_string_to_jstring(env, ph.getSenderFingerprint()); + const std::vector<std::string>& recevr_fprints = ph.getReceiverFingerprints(); + jobject jrecevr_fprints = jau::convert_vector_string_to_jarraylist(env, recevr_fprints); jau::java_exception_check_and_throw(env, E_FILE_LINE); jclass packHeaderClazz = jau::search_class(env, _packHeaderClassName.c_str()); @@ -120,25 +103,26 @@ jobject jcipherpack::to_jPackHeader(JNIEnv *env, const PackHeader& ph) { jobject jph = env->NewObject(packHeaderClazz, packHeaderClazzCtor, jtarget_path, static_cast<jlong>(ph.getContentSize()), - static_cast<jlong>(ph.getCreationTime().to_fraction_i64().to_ms()), - jintention, + static_cast<jlong>(ph.getCreationTime().tv_sec), + static_cast<jlong>(ph.getCreationTime().tv_nsec), + jsubject, jpversion, jpversion_parent, jccfg, - jpk_host_key_fprint, - jtermKeysFingerprint, - ph.getUsedTermKeyFingerprintIndex(), + jsender_fprint, + jrecevr_fprints, + ph.getUsedReceiverKeyIndex(), ph.isValid()); jau::java_exception_check_and_throw(env, E_FILE_LINE); env->DeleteLocalRef(packHeaderClazz); env->DeleteLocalRef(jtarget_path); - env->DeleteLocalRef(jintention); + env->DeleteLocalRef(jsubject); env->DeleteLocalRef(jpversion); env->DeleteLocalRef(jpversion_parent); env->DeleteLocalRef(jccfg); - env->DeleteLocalRef(jpk_host_key_fprint); - env->DeleteLocalRef(jtermKeysFingerprint); + env->DeleteLocalRef(jsender_fprint); + env->DeleteLocalRef(jrecevr_fprints); return jph; } |