The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

How note to use RSA by Nintendo...,

Last post 03-27-2008 6:13 AM by PJH. 19 replies.
Page 1 of 1 (20 items)
Sort Posts: Previous Next
  • 03-26-2008 5:24 AM

    • BOFH
    • Not Ranked
    • Joined on 07-13-2007
    • Fort Satanus MKII
    • Posts 31

    How note to use RSA by Nintendo...,

     

     

    struct rsa_cert {
    u32 key_id;
    char rsa_signature[1024];
    char metadata[32];
    char content_hash[20];
    };

    int verify_cert (struct rsa_cert cert) {
    char *cert_hash=SHA1(cert.metadata + cert.content_hash);
    char *sig_hash=rsa_decrypt(cert.rsa_signature, cert.key_id);

    if (strncmp(cert_hash, sig_hash, SHA1_LENGTH) == 0) {
    return CERT_OK;
    } else {
    return CERT_BAD;
    }
    }

    int is_a_valid_disc(struct rsa_cert cert, char *disc_hash) {
    if(memcmp(disc_hash, cert.content_hash, SHA1_LENGTH) != 0) {
    return DISC_BAD;
    }

    if(verify_cert (cert) == CERT_BAD) {
    return DISC_BAD;
    } else {
    return DISC_OK;
    }

    }
     
     

     http://wiibrew.org/index.php?title=Signing_bug

  • 03-26-2008 6:42 AM In reply to

    Re: How note to use RSA by Nintendo...,

    Um... that's not a WTF - it's a bug, probably caused by insufficient coffee.

  • 03-26-2008 7:05 AM In reply to

    • Zecc
    • Top 75 Contributor
    • Joined on 06-12-2007
    • Posts 376

    Re: How note to use RSA by Nintendo...,

    char metadata[32];
    char content_hash[20];

    [...]

    char *cert_hash=SHA1(cert.metadata + cert.content_hash);

    Ehmm... What?

     

    EDIT: oh, pointer math, never mind. 

    If mixed metaphors were illegal, I'd be having an indigestion.
  • 03-26-2008 9:03 AM In reply to

    Re: How note to use RSA by Nintendo...,

    Zecc:

    char metadata[32];
    char content_hash[20];

    [...]

    char *cert_hash=SHA1(cert.metadata + cert.content_hash);

    Ehmm... What?

     

    EDIT: oh, pointer math, never mind. 

    Pointer + pointer? Mind.
    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    Visit #TDWTF @ SlashNET - the semi-official WTF IRC channel.
  • 03-26-2008 10:01 AM In reply to

    Re: How note to use RSA by Nintendo...,

    Spectre:
    Zecc:

    char metadata[32];
    char content_hash[20];

    [...]

    char *cert_hash=SHA1(cert.metadata + cert.content_hash);

    Ehmm... What?

     

    EDIT: oh, pointer math, never mind. 

    Pointer + pointer? Mind.
     

    Pointer + pointer illegal in C? 

  • 03-26-2008 10:07 AM In reply to

    Re: How note to use RSA by Nintendo...,

    fist-poster:
    Pointer + pointer illegal in C? 
    It's perfectly legal. It's never wise unless you know where every single other piece of reserved memory is so you know the resulting pointer is someplace safe.
    irc://irc.slashnet.org/#TDWTF
    <Ling> Looks like [lotus] notes was indeed clock sucking and pissing wildly on my disk
    <Duplication_Prevention_Bot> Wow, that was a disturbing image.
  • 03-26-2008 10:23 AM In reply to

    Re: How note to use RSA by Nintendo...,

    Lingerance:
    fist-poster:
    Pointer + pointer illegal in C? 
    It's perfectly legal. It's never wise unless you know where every single other piece of reserved memory is so you know the resulting pointer is someplace safe.

     Not according to MinGW.

    int main() {
       char* a, *b, *c;
       c = a + b;
       return 0;
    }

     error: invalid operands of types 'char*' and 'char*' to binary 'operator+'

     

    c = a - (char*)(-(long long)b); // Legal C, illegal C++

  • 03-26-2008 10:28 AM In reply to

    • PJH
    • Top 25 Contributor
    • Joined on 02-14-2007
    • Posts 636

    Re: How note to use RSA by Nintendo...,

    Lingerance:
    fist-poster:
    Pointer + pointer illegal in C? 
    It's perfectly legal.
    No it isn't.

    C99 Draft (N869, 18 January, 1999):

    6.5.6 Additive operators

    [...] 

    #2

    For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integer type. (Incrementing is equivalent to adding 1.)

    #3

    For subtraction, one of the following shall hold:

    -- both operands have arithmetic type;

    -- both operands are pointers to qualified or unqualified versions of compatible object types; or

    -- the left operand is a pointer to an object type and the right operand has integer type.

    Pointers are not 'arithmetic types' (6.2.5#21)

    This is not a problem that requires infinite wisdom, Benj. This is a problem that requires enough neural organization to qualify as a vertebrate, apparently a stretch for some folks these days.
    - Cecil Adams.
  • 03-26-2008 10:29 AM In reply to

    Re: How note to use RSA by Nintendo...,

    The article referred to by the OP clearly states it is pseudocode, so it doesn't really matter whether or not you can do it.

    Most likely, the + is used to show concatenation, considering the kind of data the operands represent. I haven't explored the Wii firmware enough to know, though.

  • 03-26-2008 10:33 AM In reply to

    Re: How note to use RSA by Nintendo...,

    Pidgeot:

    The article referred to by the OP clearly states it is pseudocode, so it doesn't really matter whether or not you can do it.

    Most likely, the + is used to show concatenation, considering the kind of data the operands represent. I haven't explored the Wii firmware enough to know, though.

    Bingo.  The + is for concatentation, the example was pseudocode, the args aren't even right for SHA1() and you cannot add pointer types in C without casting one to an integral type which is just stupid. 

    < pstorer> Bans don't mean shit on the forum. It's like being on the Sex Offender List. You can still entice kids into your van with candy.

    Want more? Go the IRC channel #TDWTFMafia on irc.slashnet.org.
  • 03-26-2008 10:49 AM In reply to

    • PJH
    • Top 25 Contributor
    • Joined on 02-14-2007
    • Posts 636

    Re: How note to use RSA by Nintendo...,

    morbiuswilters:
    and you cannot add pointer types in C without casting one to an integral type which is just stupid. 
    I'm intrigued - could you give a contrived example of when adding two pointers would yield a sensible result?

    This is not a problem that requires infinite wisdom, Benj. This is a problem that requires enough neural organization to qualify as a vertebrate, apparently a stretch for some folks these days.
    - Cecil Adams.
  • 03-26-2008 11:19 AM In reply to

    Re: How note to use RSA by Nintendo...,

    PJH:
    morbiuswilters:
    and you cannot add pointer types in C without casting one to an integral type which is just stupid. 
    I'm intrigued - could you give a contrived example of when adding two pointers would yield a sensible result?

    Hmm, perhaps you are misunderstanding me.  I'm saying it would be stupid to add pointers and that you have to cast to an int just to get the compiler to accept it.  I'm not saying it's stupid that it is  illegal C.  I really cannot even think of a contrived example where you would want to do this, but I have faith that somebody will manage to come up with.

     

    Now, pointer multiplication, that is absolutely essential in my day-to-day work.

    pOffset = (char *)((unsigned long)pBuf1 * (unsigned long)pBuf2); 

    < pstorer> Bans don't mean shit on the forum. It's like being on the Sex Offender List. You can still entice kids into your van with candy.

    Want more? Go the IRC channel #TDWTFMafia on irc.slashnet.org.
  • 03-26-2008 11:51 AM In reply to

    Re: How note to use RSA by Nintendo...,

    Pidgeot:
    The article referred to by the OP clearly states it is pseudocode
    That alone a WTF it does not make unless someone takes it literally. I really wish it was possible to use a clue-by-four when the "plz send codz" people copy-paste psuedocode and reply back that it doesn't work.

    Join us at #TDWTF on irc.slashnet.org !

  • 03-26-2008 2:07 PM In reply to

    Re: How note to use RSA by Nintendo...,

    Didn't anybody see that the code uses strncmp to compare two binary buffers?

     

  • 03-26-2008 2:35 PM In reply to

    Re: How note to use RSA by Nintendo...,

    Didn't anybody see that the code uses strncmp to compare two binary buffers?
    Those of us that went to the actual article did:
    TFA:
    The bug here is that the hash can (and very likely does) contain a NULL byte, (chr)0 that is. To quote from the first google hit for strncmp: "Compares up to num characters of the C string str1 to those of the C string str2. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null-character is reached, or until num characters match in both strings, whichever happens first." This last part means that if it finds a NULL byte, it stops comparing, even if there is more data after the NULL.
  • 03-26-2008 3:46 PM In reply to

    Re: How note to use RSA by Nintendo...,

    alegr:
    Didn't anybody see that the code uses strncmp to compare two binary buffers?

    Yes, because I read TFA. That's what the OP was getting at as the real WTF.

    Of course this has been fixed, complete with a rant against Datel for using the vuln (Basically, by using it in a commercial product, Datel guaranteed Nintendo would fix it.)

    The posters of TFA basically said "yeah we knew about it, we were using it to get into the system."  Grey-hats all around there. :) 

  • 03-26-2008 9:43 PM In reply to

    Re: How note to use RSA by Nintendo...,

    vt_mruhlin:
    Didn't anybody see that the code uses strncmp to compare two binary buffers?
    Those of us that went to the actual article did:
    TFA:
    The bug here is that the hash can (and very likely does) contain a NULL byte, (chr)0 that is.
     

    TRWTF then is the poor pseudo-coding.  If "+" can mean "concatenate byte arrays", why shouldn't we assume that assigning the returned hash to a char* pointer won't invoke a conversion operator that turns it into an ASCII hex string?  The FA's author needs to grok that if you're criticising someone for being incorrect, it behooves you to be fairly damn precise about it.

     

  • 03-26-2008 10:32 PM In reply to

    Re: How note to use RSA by Nintendo...,

    DaveK:
    TRWTF then is the poor pseudo-coding.  If "+" can mean "concatenate byte arrays", why shouldn't we assume that assigning the returned hash to a char* pointer won't invoke a conversion operator that turns it into an ASCII hex string?  The FA's author needs to grok that if you're criticising someone for being incorrect, it behooves you to be fairly damn precise about it.

    It was clearly mentioned in the article that this was pseudocode, so you should not go in expecting it to be absolutely precise.  Additionaly, the actual bug was explicitly pointed out in the explanation, meaning you didn't need to read the article at all.  I suppose it made me stop for a second and wonder what the hell the code was trying to do, but concatenation was the only thing that made logical sense.  The '+' operator is used in many languages for string concatentation and since I knew I was reading pseudocode and that the pointers couldn't be added, I came to the only logical conclusion..

    < pstorer> Bans don't mean shit on the forum. It's like being on the Sex Offender List. You can still entice kids into your van with candy.

    Want more? Go the IRC channel #TDWTFMafia on irc.slashnet.org.
  • 03-26-2008 10:48 PM In reply to

    Re: How note to use RSA by Nintendo...,

    vt_mruhlin:
    Didn't anybody see that the code uses strncmp to compare two binary buffers?
    Those of us that went to the actual article did:
    TFA:
    The bug here is that the hash can (and very likely does) contain a NULL byte, (chr)0 that is. To quote from the first google hit for strncmp: "Compares up to num characters of the C string str1 to those of the C string str2. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null-character is reached, or until num characters match in both strings, whichever happens first." This last part means that if it finds a NULL byte, it stops comparing, even if there is more data after the NULL.
     

    It's still an improvement over Microsoft, who used RC4 to compute a hash over the Xbox's bootloader -- which would have been clever, if not for the fact that RC4 can't actually be used to compute hashes.

    After discovering their mistake, Microsoft switched to TEA for computing the bootloader's hash in the next Xbox revision.  Can you guess what TEA isn't supposed to be used for?

  • 03-27-2008 6:13 AM In reply to

    • PJH
    • Top 25 Contributor
    • Joined on 02-14-2007
    • Posts 636

    Re: How note to use RSA by Nintendo...,

    morbiuswilters:
    It was clearly mentioned in the article that this was pseudocode, so you should not go in expecting it to be absolutely precise. 
    If the author of the pseudocode is going to go to the effort of making it look almost, but not exactly like, C and using strncmp() then it should be using strcat() or a pseudofunction, not + for concatenation.

    Moreso, if it's pointing out a bug in actually using strncmp() instead of memcmp().


    This is not a problem that requires infinite wisdom, Benj. This is a problem that requires enough neural organization to qualify as a vertebrate, apparently a stretch for some folks these days.
    - Cecil Adams.
Page 1 of 1 (20 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems