Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decryption failed on different cipher key per PubNub instance #161

Closed
akuzminskyi opened this issue Mar 13, 2024 · 2 comments
Closed

Decryption failed on different cipher key per PubNub instance #161

akuzminskyi opened this issue Mar 13, 2024 · 2 comments

Comments

@akuzminskyi
Copy link

akuzminskyi commented Mar 13, 2024

Hi,
There is probably another issue. if there are multiple instances of PubNub with different encryption/decryption keys(cipher key), messages on the second instance of PubNub are not decryptable - looks like it is using one cryptoModule/key for for all instances. But each channel can have unique encryption/decryption keys.

func makePubNub(cryptoKey: String, subscriptionKey: String) -> PubNub {
          let cryptoModule = CryptoModule.aesCbcCryptoModule(
            with: cryptoKey,
            withRandomIV: false
        )
        let configuration = PubNubConfiguration(
            publishKey: nil,
            subscribeKey: subscriptionKey,
            userId: clientIdentifier(),
            cryptoModule: cryptoModule
        )
        return PubNub(configuration: configuration)
}

let pubNub1 =  makePubNub(cryptoKey: "keyForChannel_1", subscriptionKey: ".....")
// addListener pubNub1
pubNub1.subscribe(to: "channel_1")
// send a message to channel_1
// The message will be successfully parsed/decrypted

let pubNub2 =  makePubNub(cryptoKey: "keyForChannel_2", subscriptionKey: ".....")
// addListener to pubNub2
pubNub2.subscribe(to: "channel_2")
// send a message to channel_1
// The `channel_1` message will be successfully parsed/decrypted
// send a message to channel_2
// The `channel_2` message will failed on decryption.

Also in logs, it will be;

[Warn 2024-03-13T15:11:30.905Z (com.apple.main-thread#Thread.Main) {SubscribeRouter.decrypt(_:message:)#133}] Subscribe message failed to decrypt due to Failure to perform decryption: Cannot create String from provided Data

The message: PubNubMessageBase will have error:

▿ PubNubMessageBase
  - publisher : nil
  - channel : "uk.order.edeedxl1zuafgmaxg459oq"
  ▿ subscription : Optional<String>
    - some : "uk.order.edeedxl1zuafgmaxg459oq"
  - published : 17103427589802006
  - messageType : PubNub.PubNubMessageType.message
  ▿ error : Optional<PubNubError>
    ▿ some : Failure to perform decryption: Cannot create String from provided Data
      - reason : Failure to perform decryption
      ▿ details : 1 element
        - 0 : "Cannot create String from provided Data"
      - underlying : nil
      - coorelation : 0 elements
      - affected : 0 elements
      - router : nil
      - domain : "PubNub"
  ▿ concretePayload : Cu+JjBjKt6ommEBmWZ2zqIhlXmuSWKiZ2ta/KTckNdckK36U6I2lNbEuw75eM0zk4z68nBpK1nCTVRc8/1R2EAnOHVHU4cGLZf2xfjJdwGpOnLB4BHxMW5+3V0TFTWU9JEBBz3VD7MM9FVzfNAokCv6XSydbkJ+TAIOjOiIO9zLY8aWPDRQ0duefsJ6sq54o33bMXaoiOaioyEyqWSqypJRi86asOIhYTHu26uXrKdES5LJUYSahxZBRF8HlrSvO2hJj6edQU8q1FWDnDBGAxjAxl6xWL+wy4QrzCCsXyHnu0HUPN386zJdyRoK9/imkLsma8DGYRXM7MSj/3z6wckxmsKiBb4Og93Mux3sSP8S08nXPBOCbWJ0SKlVgYwBj4aCuWMplEnXcnEUvHDC0Bo33VA238YLMj7pbTcLgBfTM8K08vNjoeFbk8rWeScyc37g80UT9+ugME1iKOOazdMkx4jNIzTcblYe48JlGBzzdB29sTpW1tw4wc7jpxsV2U5C1CJ7YYf1t+gm7BIu2qKyWpxrBO0HfjhTYvMxu1U5qqYD3TMHoMJrqOLFXQ61O
    ▿ value : AnyJSONType
      - string : "Cu+JjBjKt6ommEBmWZ2zqIhlXmuSWKiZ2ta/KTckNdckK36U6I2lNbEuw75eM0zk4z68nBpK1nCTVRc8/1R2EAnOHVHU4cGLZf2xfjJdwGpOnLB4BHxMW5+3V0TFTWU9JEBBz3VD7MM9FVzfNAokCv6XSydbkJ+TAIOjOiIO9zLY8aWPDRQ0duefsJ6sq54o33bMXaoiOaioyEyqWSqypJRi86asOIhYTHu26uXrKdES5LJUYSahxZBRF8HlrSvO2hJj6edQU8q1FWDnDBGAxjAxl6xWL+wy4QrzCCsXyHnu0HUPN386zJdyRoK9/imkLsma8DGYRXM7MSj/3z6wckxmsKiBb4Og93Mux3sSP8S08nXPBOCbWJ0SKlVgYwBj4aCuWMplEnXcnEUvHDC0Bo33VA238YLMj7pbTcLgBfTM8K08vNjoeFbk8rWeScyc37g80UT9+ugME1iKOOazdMkx4jNIzTcblYe48JlGBzzdB29sTpW1tw4wc7jpxsV2U5C1CJ7YYf1t+gm7BIu2qKyWpxrBO0HfjhTYvMxu1U5qqYD3TMHoMJrqOLFXQ61O"
  - concreteMessageActions : 0 elements
  - concreteMetadata : nil

I checked on 6.2.3 and 7.0.0 SDK.

@jguz-pubnub
Copy link
Contributor

Hi @akuzminskyi,

This is related to the issue you mentioned before. My initial assumption is that CryptoModule has insufficient implementation for computing a hash value. I will investigate it and let you know.

@akuzminskyi
Copy link
Author

I can confirm the issue is not happening anymore in 7.1.0 for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants