Skip to content

Commit b5b9305

Browse files
committed
add SignatureAlgorithm
Signed-off-by: alperozturk <[email protected]>
1 parent cb12e46 commit b5b9305

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

library/src/androidTest/java/com/owncloud/android/lib/resources/e2ee/SendCSRRemoteOperationIT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SendCSRRemoteOperationIT : AbstractIT() {
3535
val keyPair = keyGen.genKeyPair()
3636

3737
// create CSR
38-
val urlEncoded: String = CsrHelper().generateCsrPemEncodedString(keyPair, client.userId)
38+
val urlEncoded: String = CsrHelper().generateCsrPemEncodedString(keyPair, client.userId, SignatureAlgorithm.SHA1)
3939

4040
val operation = SendCSRRemoteOperation(urlEncoded)
4141
var result = operation.execute(nextcloudClient)

library/src/main/java/com/owncloud/android/lib/resources/e2ee/CsrHelper.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ class CsrHelper {
3838
*
3939
* @param keyPair the KeyPair with private and public keys
4040
* @param userId userId of CSR owner
41+
* @param algorithm represents supported signature algorithm
4142
* @return PEM encoded CSR string
4243
* @throws IOException thrown if key cannot be created
4344
* @throws OperatorCreationException thrown if contentSigner cannot be build
4445
*/
4546
@Throws(IOException::class, OperatorCreationException::class)
4647
fun generateCsrPemEncodedString(
4748
keyPair: KeyPair,
48-
userId: String
49+
userId: String,
50+
algorithm: SignatureAlgorithm
4951
): String {
50-
val csr = generateCSR(keyPair, userId)
52+
val csr = generateCSR(keyPair, userId, algorithm)
5153
val derCSR = csr.encoded
5254
return "-----BEGIN CERTIFICATE REQUEST-----\n" +
5355
Base64.encodeToString(
@@ -61,6 +63,7 @@ class CsrHelper {
6163
*
6264
* @param keyPair the KeyPair with private and public keys
6365
* @param userId userId of CSR owner
66+
* @param algorithm represents supported signature algorithm
6467
* @return PKCS10CertificationRequest with the certificate signing request (CSR) data
6568
* @throws IOException thrown if key cannot be created
6669
* @throws OperatorCreationException thrown if contentSigner cannot be build
@@ -69,12 +72,13 @@ class CsrHelper {
6972
@Throws(IOException::class, OperatorCreationException::class)
7073
private fun generateCSR(
7174
keyPair: KeyPair,
72-
userId: String
75+
userId: String,
76+
algorithm: SignatureAlgorithm
7377
): PKCS10CertificationRequest {
7478
val principal = "CN=$userId"
7579
val privateKey = PrivateKeyFactory.createKey(keyPair.private.encoded)
76-
val signatureAlgorithm = DefaultSignatureAlgorithmIdentifierFinder().find("SHA1WITHRSA")
77-
val digestAlgorithm = DefaultDigestAlgorithmIdentifierFinder().find("SHA-1")
80+
val signatureAlgorithm = DefaultSignatureAlgorithmIdentifierFinder().find(algorithm.signatureAlg)
81+
val digestAlgorithm = DefaultDigestAlgorithmIdentifierFinder().find(algorithm.digestAlg)
7882
val signer =
7983
BcRSAContentSignerBuilder(signatureAlgorithm, digestAlgorithm).build(privateKey)
8084
val csrBuilder: PKCS10CertificationRequestBuilder =
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.e2ee
9+
10+
enum class SignatureAlgorithm(val signatureAlg: String, val digestAlg: String) {
11+
SHA1("SHA1WITHRSA", "SHA-1"),
12+
SHA256("SHA256WITHRSA", "SHA-256")
13+
}

0 commit comments

Comments
 (0)