Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
Hi Peter, ERASE and WRITE are left-overs from the old smart card days. Most - if not all - cards and applications today only implement UPDATE BINARY. There is also no common understanding that UPDATE BINARY must not extend the length of an EF. Some implementations maintain a maximum EF and a current EF size. The maximum size is typically set in CREATE FILE, whereas the current EF size depends on the amount of data written to the EF. An EF may start with no data contained and and UPDATE BINARY command with P1|P2 = Length of EF (or zero based offset after last byte ;-) appends the amount of data provided in the C-Data of the APDU. Usually gaps are not allowed, so an offset beyond end-of-file + 1 gives SW1/SW2=6B00. Other implementations allocate the full EF size at creation, so you can immediately read from the EF, even though no data has been written yet. Hope this helps, Andreas Am 07.06.2012 22:01, schrieb Peter Marschall: Hi, thanks for the quick reply/correction. On Thursday, 7. June 2012, Martin Paljak wrote: On Thu, Jun 7, 2012 at 10:35 PM, Martin Paljak mar...@martinpaljak.net wrote: Hello, On Thu, Jun 7, 2012 at 10:24 PM, Peter Marschall pe...@adpm.de wrote: Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? AFAIU either can change file size (which can be done though 7816-9). Correction, can NOT change file size. Does that mean that none of them can change the number of data elements that are in the file ? This seems to contradict the sentence in ISO 7816-4 7.2.4 WRITE BINARY which states: - the write-once of the bits given in the command data field (the command shall be aborted if thestring of data units is not in the logical erased state) To me that sentence sounds like WRITE BINARY is an operation that A) can only be used on data that is logically reset, (i.e. once WRITE_BINARY was performed, it cannot be used on the same data any more without a preceding ERASE BINARY of that region) B) can extend the number of data units in the file (this is what I sloppily called existing_file_size in my previous mail) In the other hand, ISO 7816-4 7.2.4 UPDATE BINARY says: the command initialtes the update of the bits already present in an EF ... This is what I interpret as can only update existing data units in the file, but not create more. Am I completely wrong? Are there interpretation helpers for the spec available somewhere? While I am at it: Would you mind to pull Pull Request #53 https://github.com/OpenSC/OpenSC/pull/53 into the staging branch of github's open/opensc? (It is a little bit frustrating to not get any feedback at all for a PullReq ;-) Thanks PEter -- -CardContact Software System Consulting |.## ##.| Andreas Schwier |# #| Schülerweg 38 |# #| 32429 Minden, Germany |'## ##'| Phone +49 171 8334920 -http://www.cardcontact.de http://www.tscons.de http://www.openscdp.org ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
Hi Andreas, thanks a ton. That explains it very well and answers all my questions. On Friday, 8. June 2012, Andreas Schwier (ML) wrote: Hi Peter, ERASE and WRITE are left-overs from the old smart card days. Most - if not all - cards and applications today only implement UPDATE BINARY. There is also no common understanding that UPDATE BINARY must not extend the length of an EF. Some implementations maintain a maximum EF and a current EF size. The maximum size is typically set in CREATE FILE, whereas the current EF size depends on the amount of data written to the EF. An EF may start with no data contained and and UPDATE BINARY command with P1|P2 = Length of EF (or zero based offset after last byte ;-) appends the amount of data provided in the C-Data of the APDU. Usually gaps are not allowed, so an offset beyond end-of-file + 1 gives SW1/SW2=6B00. Other implementations allocate the full EF size at creation, so you can immediately read from the EF, even though no data has been written yet. Hope this helps, Andreas Am 07.06.2012 22:01, schrieb Peter Marschall: Hi, thanks for the quick reply/correction. On Thursday, 7. June 2012, Martin Paljak wrote: On Thu, Jun 7, 2012 at 10:35 PM, Martin Paljak mar...@martinpaljak.net wrote: Hello, On Thu, Jun 7, 2012 at 10:24 PM, Peter Marschall pe...@adpm.de wrote: Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? AFAIU either can change file size (which can be done though 7816-9). Correction, can NOT change file size. Does that mean that none of them can change the number of data elements that are in the file ? This seems to contradict the sentence in ISO 7816-4 7.2.4 WRITE BINARY which states: - the write-once of the bits given in the command data field (the command shall be aborted if thestring of data units is not in the logical erased state) To me that sentence sounds like WRITE BINARY is an operation that A) can only be used on data that is logically reset, (i.e. once WRITE_BINARY was performed, it cannot be used on the same data any more without a preceding ERASE BINARY of that region) B) can extend the number of data units in the file (this is what I sloppily called existing_file_size in my previous mail) In the other hand, ISO 7816-4 7.2.4 UPDATE BINARY says: the command initialtes the update of the bits already present in an EF ... This is what I interpret as can only update existing data units in the file, but not create more. Am I completely wrong? Are there interpretation helpers for the spec available somewhere? While I am at it: Would you mind to pull Pull Request #53 https://github.com/OpenSC/OpenSC/pull/53 into the staging branch of github's open/opensc? (It is a little bit frustrating to not get any feedback at all for a PullReq ;-) Thanks PEter -- Peter Marschall pe...@adpm.de ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
[opensc-devel] questions on {ERASE,WRITE,UPDATE} BINARY commands
Hi, I have questions on the {ERASE,WRITE,UPDATE} BINARY commands for which I do not find the answer in the spec (ISO-7816-4). Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? * Is it to be considered an error if UPDATE BINARY a) uses an idx = existing_file_size ? b) wants to update 0 data elements (i.e. count = 0) ? c) idx + count = existing_file_size? * Similar for ERASE BINARY a) Can it set data elements to logical erased state beyond the file size? i.e. idx + count = existing_file_size b) Is it an error to erase 0 data alements i.e. count = 0 c) If idx + count = file_size, does the file get zapped (=shortened) to idx data elements? Thanks in advance Peter -- Peter Marschall pe...@adpm.de ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
Hello, On Thu, Jun 7, 2012 at 10:24 PM, Peter Marschall pe...@adpm.de wrote: Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? AFAIU either can change file size (which can be done though 7816-9). UPDATE will *set* the bits as given in the command, whereas WRITE can allow some bit-fiddling. Why the question? If there would be a card that implements both, I think you would want to use UPDATE, at least in the context of OpenSC, unless it is *not* supported and WRITE is supported. What exactly is the context? * Is it to be considered an error if UPDATE BINARY a) uses an idx = existing_file_size ? Probably. '6B00' (offset outside the EF) b) wants to update 0 data elements (i.e. count = 0) ? IMHO should not, but implementations might vary, of course. c) idx + count = existing_file_size? Probably. '6B00' (offset outside the EF) * Similar for ERASE BINARY a) Can it set data elements to logical erased state beyond the file size? i.e. idx + count = existing_file_size b) Is it an error to erase 0 data alements i.e. count = 0 c) If idx + count = file_size, does the file get zapped (=shortened) to idx data elements? Ditto. Martin ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
On Thu, Jun 7, 2012 at 10:35 PM, Martin Paljak mar...@martinpaljak.net wrote: Hello, On Thu, Jun 7, 2012 at 10:24 PM, Peter Marschall pe...@adpm.de wrote: Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? AFAIU either can change file size (which can be done though 7816-9). Correction, can NOT change file size. ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
Hi Martin, thanks for the quick reply. On Thursday, 7. June 2012, Martin Paljak wrote: On Thu, Jun 7, 2012 at 10:24 PM, Peter Marschall pe...@adpm.de wrote: Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? AFAIU either can change file size (which can be done though 7816-9). UPDATE will *set* the bits as given in the command, whereas WRITE can allow some bit-fiddling. Why the question? If there would be a card that implements both, I think you would want to use UPDATE, at least in the context of OpenSC, unless it is *not* supported and WRITE is supported. What exactly is the context? The wish to implement them correctly for the OpenPGP card. * Is it to be considered an error if UPDATE BINARY a) uses an idx = existing_file_size ? Probably. '6B00' (offset outside the EF) b) wants to update 0 data elements (i.e. count = 0) ? IMHO should not, but implementations might vary, of course. c) idx + count = existing_file_size? Probably. '6B00' (offset outside the EF) * Similar for ERASE BINARY a) Can it set data elements to logical erased state beyond the file size? i.e. idx + count = existing_file_size b) Is it an error to erase 0 data alements i.e. count = 0 c) If idx + count = file_size, does the file get zapped (=shortened) to idx data elements? Ditto. Martin -- Peter Marschall pe...@adpm.de ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
On Thu, Jun 7, 2012 at 10:44 PM, Peter Marschall pe...@adpm.de wrote: Why the question? If there would be a card that implements both, I think you would want to use UPDATE, at least in the context of OpenSC, unless it is *not* supported and WRITE is supported. What exactly is the context? The wish to implement them correctly for the OpenPGP card. I don't see references to UPDATE/WRITE/ERASE BINARY in OpenPGP 2.0.1 spec, only PUT DATA? See also this e-mail: http://lists.gnupg.org/pipermail/gnupg-devel/2011-May/026079.html Martin ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] questions on {ERASE, WRITE, UPDATE} BINARY commands
Hi, thanks for the quick reply/correction. On Thursday, 7. June 2012, Martin Paljak wrote: On Thu, Jun 7, 2012 at 10:35 PM, Martin Paljak mar...@martinpaljak.net wrote: Hello, On Thu, Jun 7, 2012 at 10:24 PM, Peter Marschall pe...@adpm.de wrote: Here they are: * What's the exact difference between WRITE BINARY UPDATE BINARY? My understanding of the spec is that WRITE BINARY can extend a file's size, while UPDATE BINARY can only update data elements that are already within the file (i.e. in the range [0 .. file_size-1]). Is my understanding correct or did I misunderstand the specscompletely? AFAIU either can change file size (which can be done though 7816-9). Correction, can NOT change file size. Does that mean that none of them can change the number of data elements that are in the file ? This seems to contradict the sentence in ISO 7816-4 7.2.4 WRITE BINARY which states: - the write-once of the bits given in the command data field (the command shall be aborted if thestring of data units is not in the logical erased state) To me that sentence sounds like WRITE BINARY is an operation that A) can only be used on data that is logically reset, (i.e. once WRITE_BINARY was performed, it cannot be used on the same data any more without a preceding ERASE BINARY of that region) B) can extend the number of data units in the file (this is what I sloppily called existing_file_size in my previous mail) In the other hand, ISO 7816-4 7.2.4 UPDATE BINARY says: the command initialtes the update of the bits already present in an EF ... This is what I interpret as can only update existing data units in the file, but not create more. Am I completely wrong? Are there interpretation helpers for the spec available somewhere? While I am at it: Would you mind to pull Pull Request #53 https://github.com/OpenSC/OpenSC/pull/53 into the staging branch of github's open/opensc? (It is a little bit frustrating to not get any feedback at all for a PullReq ;-) Thanks PEter -- Peter Marschall pe...@adpm.de ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel