This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.berendeev.turboanalytics | |
| import android.os.Bundle | |
| import androidx.appcompat.app.AppCompatActivity | |
| import org.berendeev.turboanalytics.databinding.ActivityMainBinding | |
| import java.time.LocalDate | |
| class MainActivity : AppCompatActivity() { | |
| private lateinit var binding: ActivityMainBinding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.berendeev.turboanalytics | |
| import timber.log.Timber | |
| import kotlin.reflect.full.findAnnotation | |
| import kotlin.reflect.full.hasAnnotation | |
| import kotlin.reflect.full.memberProperties | |
| class KochavaSender : Sender { | |
| override fun send(event: AnalyticsEvent) { | |
| val hasEventName = event::class.hasAnnotation<EventName>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.berendeev.turboanalytics | |
| class AnalyticsReporterImpl( | |
| private val firebaseSender: FirebaseSender, | |
| private val kochavaSender: KochavaSender, | |
| ) : AnalyticsReporter { | |
| override fun send(event: AnalyticsEvent) { | |
| when (event.system) { | |
| AnalyticsSystem.FIREBASE -> firebaseSender.send(event) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.berendeev.turboanalytics | |
| @Target(AnnotationTarget.PROPERTY) | |
| @Retention(AnnotationRetention.RUNTIME) | |
| annotation class EventProperty(val key: String) | |
| @Target(AnnotationTarget.CLASS) | |
| @Retention(AnnotationRetention.RUNTIME) | |
| annotation class EventName(val name: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun signData(inputStr: String): String { | |
| val privateKeyEntry = getPrivateKey() | |
| val s = Signature.getInstance(SIGNATURE_SHA256withRSA) | |
| s.initSign(privateKeyEntry.privateKey) | |
| s.update(inputStr.toByteArray()) | |
| val signatureBytes = s.sign() | |
| val signatureString = Base64.encodeToString(signatureBytes, Base64.DEFAULT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun getPrivateKey(): KeyStore.PrivateKeyEntry? { | |
| val ks = KeyStore.getInstance("AndroidKeyStore") | |
| ks.load(null) | |
| val entry = ks.getEntry(ALIAS_VERIFY_SIGNATURE, null) | |
| if (entry !is KeyStore.PrivateKeyEntry) { | |
| return null | |
| } | |
| return entry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun verifyData(input: String, signatureStr: String?): Boolean { | |
| val privateKeyEntry = getPrivateKey() ?: return false | |
| val signature = Signature.getInstance(SIGNATURE_SHA256withRSA) | |
| signature.initVerify(privateKeyEntry.certificate) | |
| signature.update(input.toByteArray()) | |
| val signatureBytes = Base64.decode(signatureStr, Base64.DEFAULT) | |
| return signature.verify(signatureBytes) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun generateKeyPair(spec: AlgorithmParameterSpec) { | |
| val kpGenerator = KeyPairGenerator | |
| .getInstance(TYPE_RSA, ANDROID_KEYSTORE_PROVIDER) | |
| kpGenerator.initialize(spec) | |
| kpGenerator.generateKeyPair() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RequiresApi(Build.VERSION_CODES.M) | |
| private fun getRsaKeySpecM(start: Date, end: Date)= | |
| KeyGenParameterSpec.Builder(ALIAS_VERIFY_SIGNATURE, KeyProperties.PURPOSE_SIGN) | |
| .setCertificateSubject(X500Principal("CN=$ALIAS_VERIFY_SIGNATURE")) | |
| .setDigests(KeyProperties.DIGEST_SHA256) | |
| .setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1) | |
| .setCertificateSerialNumber(BigInteger.valueOf(1337)) | |
| .setCertificateNotBefore(start) | |
| .setCertificateNotAfter(end) | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun getRsaKeySpecPreM(start: Date, end: Date) = | |
| KeyPairGeneratorSpec.Builder(context!!) | |
| .setAlias(ALIAS_VERIFY_SIGNATURE) | |
| .setSubject(X500Principal("CN=$ALIAS_VERIFY_SIGNATURE")) | |
| .setSerialNumber(BigInteger.valueOf(1337)) | |
| .setStartDate(start) | |
| .setEndDate(end) | |
| .build() |
NewerOlder