Skip to content

Commit 0ba35ec

Browse files
committed
release of hwsecurity-openpgp, hwsecurity-provider, hwsecurity-ui
1 parent 7b5f1af commit 0ba35ec

File tree

117 files changed

+15808
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+15808
-0
lines changed

hwsecurity-openpgp/build.gradle

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'digital.wup.android-maven-publish'
3+
apply plugin: 'org.jetbrains.dokka-android'
4+
5+
dependencies {
6+
if (rootProject.ext.has("hwSdkIncludeAsSubmodule") && rootProject.hwSdkIncludeAsSubmodule) {
7+
api project(':hwsecurity:hwsecurity')
8+
implementation project(':hwsecurity:hwsecurity-provider')
9+
} else {
10+
api project(':hwsecurity')
11+
implementation project(':hwsecurity-provider')
12+
}
13+
14+
implementation 'org.bouncycastle:bcprov-jdk15on:1.62'
15+
16+
compileOnly 'androidx.annotation:annotation:1.0.0'
17+
18+
api 'com.google.auto.value:auto-value-annotations:1.6.2'
19+
annotationProcessor 'com.google.auto.value:auto-value:1.6.2'
20+
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.6'
21+
22+
testImplementation 'junit:junit:4.12'
23+
testImplementation 'org.robolectric:robolectric:3.2.2'
24+
testImplementation 'org.mockito:mockito-core:2.18.0'
25+
}
26+
27+
android {
28+
compileSdkVersion rootProject.ext.compileSdkVersion
29+
30+
defaultConfig {
31+
minSdkVersion 14
32+
versionName rootProject.ext.hwSdkVersionName
33+
vectorDrawables.useSupportLibrary = true
34+
consumerProguardFiles 'hwsecurity-openpgp.pro'
35+
}
36+
37+
compileOptions {
38+
sourceCompatibility JavaVersion.VERSION_1_8
39+
targetCompatibility JavaVersion.VERSION_1_8
40+
}
41+
42+
// Do not abort build if lint finds errors
43+
lintOptions {
44+
abortOnError false
45+
}
46+
}
47+
48+
publishing {
49+
publications {
50+
mavenAar(MavenPublication) {
51+
groupId = 'de.cotech'
52+
artifactId = 'hwsecurity-openpgp'
53+
version = android.defaultConfig.versionName
54+
55+
from components.android
56+
57+
pom {
58+
url = 'https://hwsecurity.dev'
59+
licenses {
60+
license {
61+
name = 'Commercial'
62+
url = 'https://hwsecurity.dev/sales/'
63+
distribution = 'repo'
64+
}
65+
license {
66+
name = 'GNU General Public License, version 3'
67+
url = 'https://www.gnu.org/licenses/gpl-3.0.txt'
68+
}
69+
}
70+
organization {
71+
name = 'Confidential Technologies GmbH'
72+
url = 'https://www.cotech.de'
73+
}
74+
}
75+
}
76+
}
77+
/*
78+
* To upload release, create file gradle.properties in ~/.gradle/ with this content:
79+
*
80+
* cotechMavenName=xxx
81+
* cotechMavenPassword=xxx
82+
*/
83+
if (project.hasProperty('cotechMavenName') && project.hasProperty('cotechMavenPassword')) {
84+
println "Found cotechMavenName, cotechMavenPassword in gradle.properties!"
85+
86+
repositories {
87+
maven {
88+
credentials {
89+
username cotechMavenName
90+
password cotechMavenPassword
91+
}
92+
url = "https://maven.cotech.de"
93+
}
94+
}
95+
}
96+
}
97+
98+
dokka {
99+
outputFormat = "hugo"
100+
outputDirectory = "$buildDir/dokka/reference"
101+
sourceDirs = files('src/main/java')
102+
103+
packageOptions {
104+
prefix = "de.cotech.hw.openpgp.internal"
105+
suppress = true
106+
}
107+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# keep BC provider
2+
-keep class org.bouncycastle.jcajce.provider.** { *; }
3+
-keep class org.bouncycastle.jce.provider.** { *; }
3.84 MB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="de.cotech.hw.openpgp">
4+
5+
<application />
6+
</manifest>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (C) 2018-2019 Confidential Technologies GmbH
3+
*
4+
* You can purchase a commercial license at https://hwsecurity.dev.
5+
* Buying such a license is mandatory as soon as you develop commercial
6+
* activities involving this program without disclosing the source code
7+
* of your own applications.
8+
*
9+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
package de.cotech.hw.openpgp;
26+
27+
import de.cotech.hw.internal.transport.usb.UsbTransportException;
28+
29+
import java.nio.ByteBuffer;
30+
import java.util.Arrays;
31+
32+
import androidx.annotation.RestrictTo;
33+
import androidx.annotation.RestrictTo.Scope;
34+
35+
36+
@RestrictTo(Scope.LIBRARY_GROUP)
37+
@SuppressWarnings("WeakerAccess")
38+
public class CardCapabilities {
39+
private static final int MASK_CHAINING = 1 << 7;
40+
private static final int MASK_EXTENDED = 1 << 6;
41+
42+
private static final int STATUS_INDICATOR_NO_INFORMATION = 0x00;
43+
private static final int STATUS_INDICATOR_INITIALISATION_STATE = 0x03;
44+
private static final int STATUS_INDICATOR_OPERATIONAL_STATE = 0x05;
45+
46+
private static final byte[] EXPECTED_PROCESSING_STATUS_BYTES = {(byte) 0x90, (byte) 0x00};
47+
48+
private byte[] historicalBytes;
49+
private byte[] capabilityBytes;
50+
51+
public CardCapabilities(byte[] historicalBytes) throws UsbTransportException {
52+
if ((historicalBytes == null) || (historicalBytes[0] != 0x00)) {
53+
throw new UsbTransportException("Invalid historical bytes category indicator byte");
54+
}
55+
this.historicalBytes = historicalBytes;
56+
capabilityBytes = getCapabilitiesBytes(historicalBytes);
57+
}
58+
59+
public CardCapabilities() {
60+
capabilityBytes = null;
61+
}
62+
63+
private static byte[] getCapabilitiesBytes(byte[] historicalBytes) {
64+
// Compact TLV
65+
ByteBuffer byteBuffer = ByteBuffer.wrap(historicalBytes, 1, historicalBytes.length - 2);
66+
while (byteBuffer.hasRemaining()) {
67+
byte tl = byteBuffer.get();
68+
if (tl == 0x73) { // Capabilities TL
69+
byte[] val = new byte[3];
70+
byteBuffer.get(val);
71+
return val;
72+
}
73+
byteBuffer.position(byteBuffer.position() + (tl & 0xF));
74+
}
75+
76+
return null;
77+
}
78+
79+
public boolean hasChaining() {
80+
return capabilityBytes != null && (capabilityBytes[2] & MASK_CHAINING) != 0;
81+
}
82+
83+
public boolean hasExtended() {
84+
return capabilityBytes != null && (capabilityBytes[2] & MASK_EXTENDED) != 0;
85+
}
86+
87+
public boolean hasLifeCycleManagement() throws UsbTransportException {
88+
byte[] lastBytes = Arrays.copyOfRange(historicalBytes, historicalBytes.length - 2, historicalBytes.length);
89+
boolean hasExpectedLastBytes = Arrays.equals(lastBytes, EXPECTED_PROCESSING_STATUS_BYTES);
90+
91+
// Yk neo simply ends with 0x0000
92+
if (!hasExpectedLastBytes) {
93+
return true;
94+
}
95+
96+
int statusIndicatorByte = historicalBytes[historicalBytes.length - 3];
97+
switch (statusIndicatorByte) {
98+
case STATUS_INDICATOR_NO_INFORMATION: {
99+
return false;
100+
}
101+
case STATUS_INDICATOR_INITIALISATION_STATE:
102+
case STATUS_INDICATOR_OPERATIONAL_STATE: {
103+
return true;
104+
}
105+
default: {
106+
throw new UsbTransportException("Status indicator byte not specified in OpenPGP specification");
107+
}
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)