Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Proposal: Lightning Pre-Image Encryption Standard

17 messages, Jun 25 to Jul 26, 2019. Started by Nadav Kohen.

ZmnSCPxj (6), Nadav Kohen (3), Stepan Snigirev (3), Alexander Leishman (2), Chris Stewart (2), David A. Harding

Permalink First message in the Wayback Machine

Nadav Kohen permalink original

Hi all,

There are many applications that sell some form of data to users (e.g. a blog post, a game, live data, etc.) monetizing with Lightning. This data transfer can (and often should) be made atomic with the payment for that data using the payment pre-image. This basically entails responding to any request for data with an invoice and data that is encrypted with that invoice's payment pre-image; thus ensuring that the user gets the data if and only if they successfully pay that invoice over the lightning network. This scheme is already in use in real applications and will likely be further adopted as more lapps emerge. It would be beneficial to have an industry standard that would allow for the creation of uniform libraries for standard ln-encryption and ln-decryption.

We propose the use of AES encryption in CFB mode with no padding to plaintext. AES encryption is a widely used standard that has libraries available for most platforms and languages. CFB mode allows the encryption of arbitrary sized plaintexts, allowing us to avoid any logic for padding/unpadding. Note that with AES in CFB mode you need to provide an initialization vector (IV), and this IV must be random for every encrypted plaintext.

A data provider should respond to requests for data over a secure channel (e.g. HTTPS) with the requested data encrypted by the payment pre-image using AES in CFB mode. Encrypting with the pre-image ensures that the user only receives the data they pay for and sending over a secure channel ensures no one else who knows the pre-image receives the data.

When encrypting with the preimage, any pre-image that is 16, 24 or 32 bytes will work.

After encrypting the desired data with the payment pre-image, serialize the encrypted data by prepending the IV to the encrypted data, and then convert the sequence of bytes to a base64 string. This final base64-encoded string can be sent over the wire to the user (securly). Since the IV is a fixed-length 16 byte prefix, deserializing the base64 string is simply a matter of converting the base64 string to a sequence of bytes, setting the IV to the first 16 bytes and the ciphertext to the rest.

Optimizations:

Once the payment has been received by the data provider, they may offer the payment preimage directly to the data recipient if there is a communication channel to the user (say over a websocket). The data provider can also simply make the payment pre-image publicly available, e.g. via a public API. This is done to provide for a better user experience by reducing latency as well as reducing the amount of communication a lapp client must have with a lightning node.

Reference implementations:

   -
   JavaScript, using the Crypto-JS library:
   https://gist.github.com/torkelrogstad/4611d73567cdcbc40d1da144169c9b03
   -
   Python, using the Pycrypto library:
   https://gist.github.com/torkelrogstad/9f57c9ec2f14322a9c1ce0a863f4ad50
   -
   Java/Scala:
   https://github.com/torkelrogstad/bitcoin-s/blob/21f69158de361349a3ef1abe6f94f042af144ea9/core/src/main/scala/org/bitcoins/core/crypto/AesCrypt.scala

Acknowledgments:

   -
   Thank you to Alex Bosworth for sharing this idea with us and having a
   working implementation of this scheme at yalls.org <http://www.yalls.org>
   -
   Thank you to Torkel Rogstad for the encryption details and reference
   implementations

Best, Nadav

ZmnSCPxj in reply to Nadav Kohen permalink original

Good morning Nadav,

I have had a similar idea (although without any details as to algorithm). However, it seems to me that the data seller is trusted to actually encrypt the data honestly (rather than, say, encrypting bytes from `/dev/random`).

On the other hand, this is a good way to obsolete many "data-monetization" permissioned blockchains such as datapace, thus I approve. (and datapace does not solve the "really encrypting `/dev/random`" problem anyway)

Regards, ZmnSCPXj

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Wednesday, June 26, 2019 12:54 AM, Nadav Kohen <nadav at suredbits.com> wrote:

Quoted text (34 lines)
> Hi all,
>
> There are many applications that sell some form of data to users (e.g. a blog post, a game, live data, etc.) monetizing with Lightning. This data transfer can (and often should) be made atomic with the payment for that data using the payment pre-image. This basically entails responding to any request for data with an invoice and data that is encrypted with that invoice's payment pre-image; thus ensuring that the user gets the data if and only if they successfully pay that invoice over the lightning network. This scheme is already in use in real applications and will likely be further adopted as more lapps emerge. It would be beneficial to have an industry standard that would allow for the creation of uniform libraries for standard ln-encryption and ln-decryption.
>
> We propose the use of AES encryption in CFB mode with no padding to plaintext. AES encryption is a widely used standard that has libraries available for most platforms and languages. CFB mode allows the encryption of arbitrary sized plaintexts, allowing us to avoid any logic for padding/unpadding. Note that with AES in CFB mode you need to provide an initialization vector (IV), and this IV must be random for every encrypted plaintext.
>
> A data provider should respond to requests for data over a secure channel (e.g. HTTPS) with the requested data encrypted by the payment pre-image using AES in CFB mode. Encrypting with the pre-image ensures that the user only receives the data they pay for and sending over a secure channel ensures no one else who knows the pre-image receives the data.
>
> When encrypting with the preimage, any pre-image that is 16, 24 or 32 bytes will work.
>
> After encrypting the desired data with the payment pre-image, serialize the encrypted data by prepending the IV to the encrypted data, and then convert the sequence of bytes to a base64 string. This final base64-encoded string can be sent over the wire to the user (securly). Since the IV is a fixed-length 16 byte prefix, deserializing the base64 string is simply a matter of converting the base64 string to a sequence of bytes, setting the IV to the first 16 bytes and the ciphertext to the rest.
>
> Optimizations:
>
> Once the payment has been received by the data provider, they may offer the payment preimage directly to the data recipient if there is a communication channel to the user (say over a websocket). The data provider can also simply make the payment pre-image publicly available, e.g. via a public API. This is done to provide for a better user experience by reducing latency as well as reducing the amount of communication a lapp client must have with a lightning node.
>
> Reference implementations:
>
> -   JavaScript, using the Crypto-JS library: https://gist.github.com/torkelrogstad/4611d73567cdcbc40d1da144169c9b03
>
> -   Python, using the Pycrypto library: https://gist.github.com/torkelrogstad/9f57c9ec2f14322a9c1ce0a863f4ad50
>
> -   Java/Scala: https://github.com/torkelrogstad/bitcoin-s/blob/21f69158de361349a3ef1abe6f94f042af144ea9/core/src/main/scala/org/bitcoins/core/crypto/AesCrypt.scala
>
>
> Acknowledgments:
>
> -   Thank you to Alex Bosworth for sharing this idea with us and having a working implementation of this scheme at yalls.org
>
> -   Thank you to Torkel Rogstad for the encryption details and reference implementations
>
>
> Best,
> Nadav
Stepan Snigirev in reply to Nadav Kohen permalink original

Hi Nadav,

Nice proposal. There are two suggestions that came to my mind:

1. In your proposal the encrypted data doesn't have any authentication. I would suggest to use authenticated encryption and add HMAC-SHA256 at the end of the encrypted data (encrypt-then-mac). Then even if insecure connection is used to pass the encrypted data it cannot be changed by the attacker.

2. Any node on the route of the payment knows the preimage and can decrypt the data. It would be nice to tune the protocol in a way that only the buyer can decrypt the data. For example we could use something like this:

Let's say Bob wants to buy data from Sally. - Bob generates a random private key `b` and corresponding public key `B`. Then he tells Sally what data he is interested in and also tells his public key `B` - Sally generates a random private key `s` and corresponding public key `S`. She calculates a secret key `k=ECDH(B, S)`, encrypts the data with it and sends encrypted (and authenticated) data to Bob. - Sally generates the invoice with the preimage `S` (i.e. x-coordinate of this point to make it 32-bytes long) - When Bob pays this invoice he learns the value of the public key `S` and can use his private key `b` to derive the encryption key `k=ECDH(B, S)`. Bob can decrypt the data now. - No one else learns the key.

Cheers, Stepan.

ZmnSCPxj in reply to Stepan Snigirev permalink original

Good morning Stepan, and Nadav,

Both additions seem good idea to me.

Quoted text (1 line)
> - Sally generates the invoice with the preimage `S` (i.e. x-coordinate of this point to make it 32-bytes long)

Does this require Bob to attempt both positive and negative sign for the y-coordinate? Alternately we can force Sally to always use a scalar such that generated point has a fixed sign (or some other property to derive the sign of the missing coordinate).

Regards, ZmnSCPxj

Stepan Snigirev in reply to ZmnSCPxj permalink original

Hi ZmnSCPxj,

Quoted text (5 lines)
> Does this require Bob to attempt both positive and negative sign for the
y-coordinate?
> Alternately we can force Sally to always use a scalar such that generated
point has a fixed sign (or some other property to derive the sign of the
missing coordinate).

The best would be if Sally uses the point with a fixed sign, then Bob doesn't need to try twice and can start decrypting data from stream (for example if it's a DRM key for a movie). Similar approach is used for R-encoding in Schnorr signatures, so we could use the same convention here.

On Tue, Jun 25, 2019 at 10:18 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (16 lines)
> Good morning Stepan, and Nadav,
>
> Both additions seem good idea to me.
>
> > - Sally generates the invoice with the preimage `S` (i.e. x-coordinate
> of this point to make it 32-bytes long)
>
> Does this require Bob to attempt both positive and negative sign for the
> y-coordinate?
> Alternately we can force Sally to always use a scalar such that generated
> point has a fixed sign (or some other property to derive the sign of the
> missing coordinate).
>
> Regards,
> ZmnSCPxj
>
ZmnSCPxj in reply to Stepan Snigirev permalink original

Thank you for your thought.

Another idea: would it be useful to split up large data (several megabytes long) and FEC-encode it in chunks (with each chunk having a separate MAC)?

That way even if some error occurs during transmission, it is possible to recover without re-downloading entire dataset. Especially, since we need to decrypt first, before we can confirm the MAC: if the MAC fails for the chunk, it's better if we can use data from nearby chunks to recover, rather than download and re-decrypt again. Or is this over-engineering?

Regards, ZmnSCPxj

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Wednesday, June 26, 2019 1:41 PM, Stepan Snigirev <snigirev.stepan at gmail.com> wrote:

Quoted text (21 lines)
> Hi ZmnSCPxj,
>
> > Does this require Bob to attempt both positive and negative sign for the y-coordinate?
> > Alternately we can force Sally to always use a scalar such that generated point has a fixed sign (or some other property to derive the sign of the missing coordinate).
>
> The best would be if Sally uses the point with a fixed sign, then Bob doesn't need to try twice and can start decrypting data from stream (for example if it's a DRM key for a movie).
> Similar approach is used for R-encoding in Schnorr signatures, so we could use the same convention here.
>
> On Tue, Jun 25, 2019 at 10:18 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
> > Good morning Stepan, and Nadav,
> >
> > Both additions seem good idea to me.
> >
> > > - Sally generates the invoice with the preimage `S` (i.e. x-coordinate of this point to make it 32-bytes long)
> >
> > Does this require Bob to attempt both positive and negative sign for the y-coordinate?
> > Alternately we can force Sally to always use a scalar such that generated point has a fixed sign (or some other property to derive the sign of the missing coordinate).
> >
> > Regards,
> > ZmnSCPxj
Stepan Snigirev in reply to ZmnSCPxj permalink original
Quoted text (3 lines)
> Another idea: would it be useful to split up large data (several
megabytes long) and FEC-encode it in chunks (with each chunk having a
separate MAC)?

I think it's a great idea. Ideally we want to do error correction and check MAC before decryption, so for large data it makes a lot of sense to split it into smaller chunks and MAC each of them. Then the receiver should use error correction to deal with errors, check MAC of the chunk and *only then* decrypt it. But it depends on the application and communication channel, so I would leave these details to the app developers.

P.S. It would be nice to have this proposal and other interesting ideas from the mailing list in some kind of guidelines for different lightning use-cases, but I feel like BOLTs repo is the wrong place to put it. Could we organize some kind of lightning-guidelines repo for lapp developers? I think it would be very useful.

Regards, Stepan.

ZmnSCPxj in reply to Stepan Snigirev permalink original

Good morning Stepan,

Quoted text (1 line)
> But it depends on the application and communication channel, so I would leave these details to the app developers.

I would mildly disagree, as I worry about proliferation of incompatible applications, or applications that can only work with specific wallets.

Still, it can be argued that this is early times for such applications, and the extra creativity may be more important for exploring the space than a premature optimization of working on a single standard.

Quoted text (2 lines)
>
> P.S. It would be nice to have this proposal and other interesting ideas from the mailing list in some kind of guidelines for different lightning use-cases, but I feel like BOLTs repo is the wrong place to put it. Could we organize some kind of lightning-guidelines repo for lapp developers? I think it would be very useful.

This seems a good idea.

Perhaps we can add Lightning Application Protocol Proposals (LAPP) repository somewhere. This would be dependent on BOLT, but BOLT would not depend on LAPP.

Probably the existing protocols like WebLN and Thor would be in scope for this.

---

On the original topic:

A concern I raised is the issue that data providers must be trusted to actually provide the data. Unfortunately, I cannot derive a good way for a data consumer to prove that the data given by a data provider is bogus. It becomes an assertion and counter-assertion (the problem with reputation systems).

An escrow system might be useful, but requires us to have some way of integrating escrow with proof-of-payment. (and it seems we need to *really* switch to payment points / scalars to combine proof-of-payment with a lot of features... this is delayed by Bitcoin getting Schnorr, unless we want to step up now and use 2p-ECDSA today, then reimplement under Schnorr when Bitcoin gets it (my understanding is that Schnorr Scriptless Script has more security than 2p-ECDSA Scriptless Script, though I am not a mathist and cannot show this))

Regards, ZmnSCPxj

Nadav Kohen in reply to ZmnSCPxj permalink original

Hi ZmnSCPxj and Stepan,

Thanks for all the feedback!

I think doing encrypt-then-mac on chunks of the data would be a great addition for users to be able to authenticate that they received the intended data.

Quoted text (3 lines)
> Any node on the route of the payment knows the preimage and can decrypt
the data. It would be nice to tune the protocol in a way that only the
buyer can decrypt the data. For example we could use something like this:

Is this not covered by sending over the pre-image encrypted data over a secure channel such as HTTPS? If anyone along the route who learns the pre-image does intercept the message with the encrypted data, that data will already be encrypted for the intended recipient right?

Quoted text (2 lines)
> Perhaps we can add Lightning Application Protocol Proposals (LAPP)
repository somewhere.

I agree that it would be awesome if there was a good place to put these kinds of proposals on a git repository someplace!

And finally in reply to all things about trusting the data provider, this proposal is intended for use cases in which a data provider is trusted (for example, DLC oracle signatures). Of course it would be super interesting if there was any way to do this with any kind of validation on the encrypted data before payment.

Best, Nadav

On Wed, Jun 26, 2019 at 4:36 AM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (51 lines)
> Good morning Stepan,
>
> > But it depends on the application and communication channel, so I would
> leave these details to the app developers.
>
> I would mildly disagree, as I worry about proliferation of incompatible
> applications, or applications that can only work with specific wallets.
>
> Still, it can be argued that this is early times for such applications,
> and the extra creativity may be more important for exploring the space than
> a premature optimization of working on a single standard.
>
> >
> > P.S. It would be nice to have this proposal and other interesting ideas
> from the mailing list in some kind of guidelines for different lightning
> use-cases, but I feel like BOLTs repo is the wrong place to put it. Could
> we organize some kind of lightning-guidelines repo for lapp developers? I
> think it would be very useful.
>
> This seems a good idea.
>
> Perhaps we can add Lightning Application Protocol Proposals (LAPP)
> repository somewhere.
> This would be dependent on BOLT, but BOLT would not depend on LAPP.
>
> Probably the existing protocols like WebLN and Thor would be in scope for
> this.
>
> ---
>
> On the original topic:
>
> A concern I raised is the issue that data providers must be trusted to
> actually provide the data.
> Unfortunately, I cannot derive a good way for a data consumer to prove
> that the data given by a data provider is bogus.
> It becomes an assertion and counter-assertion (the problem with reputation
> systems).
>
> An escrow system might be useful, but requires us to have some way of
> integrating escrow with proof-of-payment.
> (and it seems we need to *really* switch to payment points / scalars to
> combine proof-of-payment with a lot of features... this is delayed by
> Bitcoin getting Schnorr, unless we want to step up now and use 2p-ECDSA
> today, then reimplement under Schnorr when Bitcoin gets it (my
> understanding is that Schnorr Scriptless Script has more security than
> 2p-ECDSA Scriptless Script, though I am not a mathist and cannot show this))
>
> Regards,
> ZmnSCPxj
>
ZmnSCPxj in reply to Nadav Kohen permalink original

Good morning Nadav et al.,

Quoted text (3 lines)
> > Any node on the route of the payment knows the preimage and can decrypt the data. It would be nice to tune the protocol in a way that only the buyer can decrypt the data. For example we could use something like this:
>
> Is this not covered by sending over the pre-image encrypted data over a secure channel such as HTTPS? If anyone along the route who learns the pre-image does intercept the message with the encrypted data, that data will already be encrypted for the intended recipient right?

True, but the added protection allows sending the option of sending data over a non-secure channel. In particular, a secure channel like HTTPS would impose an encryption/decryption overhead, and then you will *also* encrypt/decrypt at the application layer i.e. you are encrypting twice. If you have the choice of using an insecure channel, you could take that and only have the encrypt/decrypt overhead only for the preimage-encrypted data.

i.e. with this, you have the option of sending over both secure and insecure channels. It does not hinder use of secure channel, but enables use of insecure channel. Putting MAC inside the encryption would help ensure that we can detect data replacement over insecure channel, and use of shared secret ensures only intended recipient can decrypt.

Regards, ZmnSCPxj

Alexander Leishman in reply to ZmnSCPxj permalink original

Nadav,

This is an interesting proposal, but because this still requires the customer to trust the merchant, I am concerned that it adds complexity without any meaningful guarantee to the customer. Perhaps it makes sense to at least include some extension field here that allows the merchant to include a ZKP for ZKCP-compatible data transfers? However, there are a number of limitations <http://stevengoldfeder.com/papers/ZKCSP.pdf> to consider with those.

My two cents, is that the proposed standard would only be useful for the edge case where a customer wants to pre-download the data before paying, but still trusts the merchant. What's the main use you see for that? My gut tells me there's a higher-level abstraction here to be standardized that would handle more mainstream use-cases.

ZmnSCPxj,

Quoted text (3 lines)
> Putting MAC inside the encryption would help ensure that we can detect
data replacement over insecure channel, and use of shared secret ensures
only intended recipient can decrypt.

Generally you want to MAC the ciphertext + IV, otherwise you lose ciphertext integrity guarantees. Why do you want to MAC, then encrypt?

-Alex

On Wed, Jun 26, 2019 at 4:55 PM ZmnSCPxj via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:

Quoted text (36 lines)
> Good morning Nadav et al.,
>
> > > Any node on the route of the payment knows the preimage and can
> decrypt the data. It would be nice to tune the protocol in a way that only
> the buyer can decrypt the data. For example we could use something like
> this:
> >
> > Is this not covered by sending over the pre-image encrypted data over a
> secure channel such as HTTPS? If anyone along the route who learns the
> pre-image does intercept the message with the encrypted data, that data
> will already be encrypted for the intended recipient right?
>
> True, but the added protection allows sending the option of sending data
> over a non-secure channel.
> In particular, a secure channel like HTTPS would impose an
> encryption/decryption overhead, and then you will *also* encrypt/decrypt at
> the application layer i.e. you are encrypting twice.
> If you have the choice of using an insecure channel, you could take that
> and only have the encrypt/decrypt overhead only for the preimage-encrypted
> data.
>
> i.e. with this, you have the option of sending over both secure and
> insecure channels.
> It does not hinder use of secure channel, but enables use of insecure
> channel.
> Putting MAC inside the encryption would help ensure that we can detect
> data replacement over insecure channel, and use of shared secret ensures
> only intended recipient can decrypt.
>
> Regards,
> ZmnSCPxj
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Chris Stewart in reply to Alexander Leishman permalink original

Hey Alex,

I think the benefit here is in reducing the client-server interaction for REST apis while still ensuring payment to the merchant.

Let's assume that we don't have this scheme, and want to provide a monetized REST API. The workflow looks like this, which is similar to what our behavior is now at Suredbits with websockets <https://suredbits.com/ws-playground/>.

1. Client sends request to server for invoice 2. Server returns invoice 3. Client pays invoice 4. Server sends data back, or client makes request _again_ to a server and then server returns data

With Nadav's scheme this is simplified to

1. Client sends request to server
2. Serves returns invoice, and encrypted payload
3. Client pays invoice
4. Client decrypts data according to Nadav's scheme

This saves a round trip between the server and client. It also gives atomicity to the transaction, although as you stated before there is no guarantees about integrity of the encrypted data. This is generally a hard problem to solve in the technical sense, but I think the reputational harm of the server sending bad data will be enough to prevent this, who wants to do business with some one that isn't providing the advertised service? This is a interaction that is could be repeated thousands of times on a daily basis.

-Chris

On Thu, Jul 4, 2019 at 5:18 PM Alexander Leishman <leishman3 at gmail.com> wrote:

Quoted text (72 lines)
> Nadav,
>
> This is an interesting proposal, but because this still requires the
> customer to trust the merchant, I am concerned that it adds complexity
> without any meaningful guarantee to the customer. Perhaps it makes sense to
> at least include some extension field here that allows the merchant to
> include a ZKP for ZKCP-compatible data transfers? However, there are a number
> of limitations <http://stevengoldfeder.com/papers/ZKCSP.pdf> to consider
> with those.
>
> My two cents, is that the proposed standard would only be useful for the
> edge case where a customer wants to pre-download the data before paying,
> but still trusts the merchant. What's the main use you see for that? My gut
> tells me there's a higher-level abstraction here to be standardized that
> would handle more mainstream use-cases.
>
> ZmnSCPxj,
>
> > Putting MAC inside the encryption would help ensure that we can detect
> data replacement over insecure channel, and use of shared secret ensures
> only intended recipient can decrypt.
>
> Generally you want to MAC the ciphertext + IV, otherwise you lose
> ciphertext integrity guarantees. Why do you want to MAC, then encrypt?
>
> -Alex
>
>
> On Wed, Jun 26, 2019 at 4:55 PM ZmnSCPxj via Lightning-dev <
> lightning-dev at lists.linuxfoundation.org> wrote:
>
>> Good morning Nadav et al.,
>>
>> > > Any node on the route of the payment knows the preimage and can
>> decrypt the data. It would be nice to tune the protocol in a way that only
>> the buyer can decrypt the data. For example we could use something like
>> this:
>> >
>> > Is this not covered by sending over the pre-image encrypted data over a
>> secure channel such as HTTPS? If anyone along the route who learns the
>> pre-image does intercept the message with the encrypted data, that data
>> will already be encrypted for the intended recipient right?
>>
>> True, but the added protection allows sending the option of sending data
>> over a non-secure channel.
>> In particular, a secure channel like HTTPS would impose an
>> encryption/decryption overhead, and then you will *also* encrypt/decrypt at
>> the application layer i.e. you are encrypting twice.
>> If you have the choice of using an insecure channel, you could take that
>> and only have the encrypt/decrypt overhead only for the preimage-encrypted
>> data.
>>
>> i.e. with this, you have the option of sending over both secure and
>> insecure channels.
>> It does not hinder use of secure channel, but enables use of insecure
>> channel.
>> Putting MAC inside the encryption would help ensure that we can detect
>> data replacement over insecure channel, and use of shared secret ensures
>> only intended recipient can decrypt.
>>
>> Regards,
>> ZmnSCPxj
>> _______________________________________________
>> Lightning-dev mailing list
>> Lightning-dev at lists.linuxfoundation.org
>> https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
ZmnSCPxj in reply to Chris Stewart permalink original

Good morning Alexander,

Quoted text (3 lines)
> > > Putting MAC inside the encryption would help ensure that we can detect data replacement over insecure channel, and use of shared secret ensures only intended recipient can decrypt.
> >
> > Generally you want to MAC the ciphertext + IV, otherwise you lose ciphertext integrity guarantees. Why do you want to MAC, then encrypt?

It is possible I simply misunderstand the proper use of MAC, so I shall research it in more depth.

Quoted text (17 lines)
> I think the benefit here is in reducing the client-server interaction for REST apis while still ensuring payment to the merchant.
>
> Let's assume that we don't have this scheme, and want to provide a monetized REST API. The workflow looks like this, which is similar to what our behavior is now at Suredbits with websockets.
>
> 1. Client sends request to server for invoice
> 2. Server returns invoice
> 3. Client pays invoice
> 4. Server sends data back, or client makes request _again_ to a server and then server returns data
>
> With Nadav's scheme this is simplified to
>
> 1. Client sends request to server
> 2. Serves returns invoice, and encrypted payload
> 3. Client pays invoice
> 4. Client decrypts data according to Nadav's scheme
>
> This saves a round trip between the server and client. It also gives atomicity to the transaction, although as you stated before there is no guarantees about integrity of the encrypted data. This is generally a hard problem to solve in the technical sense, but I think the reputational harm of the server sending bad data will be enough to prevent this, who wants to do business with some one that isn't providing the advertised service? This is a interaction that is could be repeated thousands of times on a daily basis.

A client can easily DoS the server by requesting and requesting (thus convincing the server to encrypt and send data immediately) and never paying. Whereas the first would require more resources on the client side, as the server does not encrypt (or never encrypts at all) until the client has shown proof-of-payment.

Regards, ZmnSCPxj

Alexander Leishman in reply to ZmnSCPxj permalink original

Chris,

Thanks for that explanation. I could see how this makes sense for lightweight data payloads because it reduces the round trip count, but I agree with ZmnSCPxj that this could pose a DoS risk for larger data payloads. This DoS risk is even more magnified for ZKCPs.

I would guess that APIs selling data for lightning payments might take different approaches:

1. You could purchase an auth token upfront that allows you access for some amount of time of some number of requests (seems to be the most efficient for APIs that would be called more than once) 2. You could pay per request (good for when you would want 1 big blob of data)

So for the case where a customer is calling the API multiple times per day, wouldn't it make more sense to pay upfront for future requests?

Best, Alex

Best, Alex

On Thu, Jul 4, 2019 at 8:36 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (52 lines)
> Good morning Alexander,
>
> > > > Putting MAC inside the encryption would help ensure that we can
> detect data replacement over insecure channel, and use of shared secret
> ensures only intended recipient can decrypt.
> > >
> > > Generally you want to MAC the ciphertext + IV, otherwise you lose
> ciphertext integrity guarantees. Why do you want to MAC, then encrypt?
>
> It is possible I simply misunderstand the proper use of MAC, so I shall
> research it in more depth.
>
>
> > I think the benefit here is in reducing the client-server interaction
> for REST apis while still ensuring payment to the merchant.
> >
> > Let's assume that we don't have this scheme, and want to provide a
> monetized REST API. The workflow looks like this, which is similar to what
> our behavior is now at Suredbits with websockets.
> >
> > 1. Client sends request to server for invoice
> > 2. Server returns invoice
> > 3. Client pays invoice
> > 4. Server sends data back, or client makes request _again_ to a server
> and then server returns data
> >
> > With Nadav's scheme this is simplified to
> >
> > 1. Client sends request to server
> > 2. Serves returns invoice, and encrypted payload
> > 3. Client pays invoice
> > 4. Client decrypts data according to Nadav's scheme
> >
> > This saves a round trip between the server and client. It also gives
> atomicity to the transaction, although as you stated before there is no
> guarantees about integrity of the encrypted data. This is generally a hard
> problem to solve in the technical sense, but I think the reputational harm
> of the server sending bad data will be enough to prevent this, who wants to
> do business with some one that isn't providing the advertised service? This
> is a interaction that is could be repeated thousands of times on a daily
> basis.
>
> A client can easily DoS the server by requesting and requesting (thus
> convincing the server to encrypt and send data immediately) and never
> paying.
> Whereas the first would require more resources on the client side, as the
> server does not encrypt (or never encrypts at all) until the client has
> shown proof-of-payment.
>
> Regards,
> ZmnSCPxj
>
David A. Harding in reply to ZmnSCPxj permalink original

On Fri, Jul 05, 2019 at 03:36:37AM +0000, ZmnSCPxj via Lightning-dev wrote:

Quoted text (3 lines)
> A client can easily DoS the server by requesting and requesting (thus
> convincing the server to encrypt and send data immediately) and never
> paying.

Is this an actual concern? Assuming this protocol is used with web apps for sites that are available over HTTPS, the client can just request the order form page over and over to also waste server CPU encrypting and bandwidth transfering (or they could use more clever ways to abuse TLS).

For the case of a downloaded file, the server can encrypt immediately before it puts data in the TCP queue so that, if the socket blocks (because the client isn't downloading), it only wasted CPU encrypting a few more blocks than were actually delivered.

-Dave

Chris Stewart in reply to Alexander Leishman permalink original
Quoted text (3 lines)
> You could purchase an auth token upfront that allows you access for some
amount of time of some number of requests (seems to be the most efficient
for APIs that would be called more than once)

This does have privacy implications. It is yet to be seen how these things develop, but this obviously allows the server to correlate what sort of data some one is interested in. However on a practical level it may super easy to correlate what sort of data people are querying for with normal heuristics.

The other thing is the accounting question, where if a person does not use all of their allocated requests within the given time frame. Perhaps you can allow a refund invoice to be provided up front, so the server can refund the user of the API after a set amount of time, but that comes with it's own issues.

We are already making the assumption that someone has a Lightning node setup, I don't see why a user wouldn't leverage that fact to not overpay for services. There could be an argument made for latency sensitive applications, but you probably want to go with a dedicated provider with colocation and a more traditional payment system if that is the case.

I agree with David Harding's analysis on DoS issues. This seems like a pretty solvable engineering problem from the server's perspective in my opinion.

-Chris

On Fri, Jul 5, 2019 at 12:34 PM Alexander Leishman <leishman3 at gmail.com> wrote:

Quoted text (82 lines)
> Chris,
>
> Thanks for that explanation. I could see how this makes sense for
> lightweight data payloads because it reduces the round trip count, but I
> agree with ZmnSCPxj that this could pose a DoS risk for larger data
> payloads. This DoS risk is even more magnified for ZKCPs.
>
> I would guess that APIs selling data for lightning payments might take
> different approaches:
>
> 1. You could purchase an auth token upfront that allows you access for
> some amount of time of some number of requests (seems to be the most
> efficient for APIs that would be called more than once)
> 2. You could pay per request (good for when you would want 1 big blob of
> data)
>
> So for the case where a customer is calling the API multiple times per
> day, wouldn't it make more sense to pay upfront for future requests?
>
> Best,
> Alex
>
> Best,
> Alex
>
>
>
> On Thu, Jul 4, 2019 at 8:36 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
>> Good morning Alexander,
>>
>> > > > Putting MAC inside the encryption would help ensure that we can
>> detect data replacement over insecure channel, and use of shared secret
>> ensures only intended recipient can decrypt.
>> > >
>> > > Generally you want to MAC the ciphertext + IV, otherwise you lose
>> ciphertext integrity guarantees. Why do you want to MAC, then encrypt?
>>
>> It is possible I simply misunderstand the proper use of MAC, so I shall
>> research it in more depth.
>>
>>
>> > I think the benefit here is in reducing the client-server interaction
>> for REST apis while still ensuring payment to the merchant.
>> >
>> > Let's assume that we don't have this scheme, and want to provide a
>> monetized REST API. The workflow looks like this, which is similar to what
>> our behavior is now at Suredbits with websockets.
>> >
>> > 1. Client sends request to server for invoice
>> > 2. Server returns invoice
>> > 3. Client pays invoice
>> > 4. Server sends data back, or client makes request _again_ to a server
>> and then server returns data
>> >
>> > With Nadav's scheme this is simplified to
>> >
>> > 1. Client sends request to server
>> > 2. Serves returns invoice, and encrypted payload
>> > 3. Client pays invoice
>> > 4. Client decrypts data according to Nadav's scheme
>> >
>> > This saves a round trip between the server and client. It also gives
>> atomicity to the transaction, although as you stated before there is no
>> guarantees about integrity of the encrypted data. This is generally a hard
>> problem to solve in the technical sense, but I think the reputational harm
>> of the server sending bad data will be enough to prevent this, who wants to
>> do business with some one that isn't providing the advertised service? This
>> is a interaction that is could be repeated thousands of times on a daily
>> basis.
>>
>> A client can easily DoS the server by requesting and requesting (thus
>> convincing the server to encrypt and send data immediately) and never
>> paying.
>> Whereas the first would require more resources on the client side, as the
>> server does not encrypt (or never encrypts at all) until the client has
>> shown proof-of-payment.
>>
>> Regards,
>> ZmnSCPxj
>>
>
Nadav Kohen in reply to Chris Stewart permalink original

Hey all,

The following is a link to the documentation for what we've been calling a *PAID* (Payment-Atomic Information Decryption) *API*: https://test.suredbits.com/api/#historical-prices-data-api-2 despite what the docs say it is currently only working on testnet, but should be on mainnet within a week. Note, that this API implements the original proposal and we plan on iterating on this to integrate all of the great amendments in this thread.

Here is an example client that can be used to query this API and decrypt the returned data once the pre-image has been recovered: https://github.com/Suredbits/sb-api#jsts-client-library-for-suredbits-apis

Best, Nadav

On Mon, Jul 8, 2019 at 6:49 AM Chris Stewart <chris at suredbits.com> wrote:

Quoted text (117 lines)
> > You could purchase an auth token upfront that allows you access for some
> amount of time of some number of requests (seems to be the most efficient
> for APIs that would be called more than once)
>
> This does have privacy implications. It is yet to be seen how these things
> develop, but this obviously allows the server to correlate what sort of
> data some one is interested in. However on a practical level it may super
> easy to correlate what sort of data people are querying for with normal
> heuristics.
>
> The other thing is the accounting question, where if a person does not use
> all of their allocated requests within the given time frame. Perhaps you
> can allow a refund invoice to be provided up front, so the server can
> refund the user of the API after a set amount of time, but that comes with
> it's own issues.
>
> We are already making the assumption that someone has a Lightning node
> setup, I don't see why a user wouldn't leverage that fact to not overpay
> for services. There could be an argument made for latency sensitive
> applications, but you probably want to go with a dedicated provider with
> colocation and a more traditional payment system if that is the case.
>
> I agree with David Harding's analysis on DoS issues. This seems like a
> pretty solvable engineering problem from the server's perspective in my
> opinion.
>
> -Chris
>
> On Fri, Jul 5, 2019 at 12:34 PM Alexander Leishman <leishman3 at gmail.com>
> wrote:
>
>> Chris,
>>
>> Thanks for that explanation. I could see how this makes sense for
>> lightweight data payloads because it reduces the round trip count, but I
>> agree with ZmnSCPxj that this could pose a DoS risk for larger data
>> payloads. This DoS risk is even more magnified for ZKCPs.
>>
>> I would guess that APIs selling data for lightning payments might take
>> different approaches:
>>
>> 1. You could purchase an auth token upfront that allows you access for
>> some amount of time of some number of requests (seems to be the most
>> efficient for APIs that would be called more than once)
>> 2. You could pay per request (good for when you would want 1 big blob of
>> data)
>>
>> So for the case where a customer is calling the API multiple times per
>> day, wouldn't it make more sense to pay upfront for future requests?
>>
>> Best,
>> Alex
>>
>> Best,
>> Alex
>>
>>
>>
>> On Thu, Jul 4, 2019 at 8:36 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>>
>>> Good morning Alexander,
>>>
>>> > > > Putting MAC inside the encryption would help ensure that we can
>>> detect data replacement over insecure channel, and use of shared secret
>>> ensures only intended recipient can decrypt.
>>> > >
>>> > > Generally you want to MAC the ciphertext + IV, otherwise you lose
>>> ciphertext integrity guarantees. Why do you want to MAC, then encrypt?
>>>
>>> It is possible I simply misunderstand the proper use of MAC, so I shall
>>> research it in more depth.
>>>
>>>
>>> > I think the benefit here is in reducing the client-server interaction
>>> for REST apis while still ensuring payment to the merchant.
>>> >
>>> > Let's assume that we don't have this scheme, and want to provide a
>>> monetized REST API. The workflow looks like this, which is similar to what
>>> our behavior is now at Suredbits with websockets.
>>> >
>>> > 1. Client sends request to server for invoice
>>> > 2. Server returns invoice
>>> > 3. Client pays invoice
>>> > 4. Server sends data back, or client makes request _again_ to a server
>>> and then server returns data
>>> >
>>> > With Nadav's scheme this is simplified to
>>> >
>>> > 1. Client sends request to server
>>> > 2. Serves returns invoice, and encrypted payload
>>> > 3. Client pays invoice
>>> > 4. Client decrypts data according to Nadav's scheme
>>> >
>>> > This saves a round trip between the server and client. It also gives
>>> atomicity to the transaction, although as you stated before there is no
>>> guarantees about integrity of the encrypted data. This is generally a hard
>>> problem to solve in the technical sense, but I think the reputational harm
>>> of the server sending bad data will be enough to prevent this, who wants to
>>> do business with some one that isn't providing the advertised service? This
>>> is a interaction that is could be repeated thousands of times on a daily
>>> basis.
>>>
>>> A client can easily DoS the server by requesting and requesting (thus
>>> convincing the server to encrypt and send data immediately) and never
>>> paying.
>>> Whereas the first would require more resources on the client side, as
>>> the server does not encrypt (or never encrypts at all) until the client has
>>> shown proof-of-payment.
>>>
>>> Regards,
>>> ZmnSCPxj
>>>
>> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>