Code Monkey home page Code Monkey logo

freefare's People

Contributors

clausecker avatar graynk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

freefare's Issues

Ultralight C identifies incorrectly causing panic

Just got my ACR122 with a pack of Mifare Classic 1k and Ultralight C.

Classic gets recognized correctly without a problem. However, with Ultralight C it panics in wrapTag method, because tag.Type() returns 6, not 1. I jury rigged tag types enum for my case and it works now, but you should probably look into it.

Key derivation support

I'm looking at this example of libfreefare and I can't find any function for mifare_ultralightc_set_key in UltralightTag, nor is there a MifareKeyDeriver. Are there any plans to add the support for this?
Here's the commit with most of the changes.

Type error

I try to use you package, but I recive some type error:

$ go get -v ./...
github.com/fuzxxl/freefare/0.3/freefare
# github.com/fuzxxl/freefare/0.3/freefare
../../fuzxxl/freefare/0.3/freefare/tag.go:137:31: cannot use *tagptr (type _Ctype_FreefareTag) as type _Ctype_MifareTag in argument to wrapTag
../../fuzxxl/freefare/0.3/freefare/tag.go:141:10: cannot use (*_Ctype_MifareTag)(unsafe.Pointer(iptr)) (type *_Ctype_MifareTag) as type *_Ctype_FreefareTag in assignment
../../fuzxxl/freefare/0.3/freefare/tag.go:160:42: cannot use *cinfo (type _Ctype_struct___8) as type _Ctype_struct___5 in assignment
../../fuzxxl/freefare/0.3/freefare/tag.go:172:16: cannot use ctag (type _Ctype_FreefareTag) as type _Ctype_MifareTag in argument to wrapTag

Go version:

$ go version
go version go1.12.4 linux/amd64

DESFireTag ReadData returning all zeros

I'm going to do some more debugging, but I figured I would throw this up here in case anyone can quickly point out something I'm doing wrong.

I am using this library to write a standard data file with 32 bytes of data to a newly created application on a DESFire target:

// Ensure we're on the master application
log.Infof("Switching to the master application...")
if err = target.SelectApplication(mAppId); err != nil {
	return err
}

// Authenticate to the target
log.Infof("Authenticating to tag...")
if err = target.Authenticate(0, *defaultDESFireDESKey); err != nil {
	return err
}

// Create the application
log.Infof("Creating application in slot %d...", realm.Slot)
if err = target.CreateApplication(appId, initialApplicationSettings, 4|freefare.CryptoAES); err != nil {
	return err
}

// Select the newly created application
log.Infof("Selecting application...")
if err = target.SelectApplication(appId); err != nil {
	return err
}

// Authenticate to the application
log.Infof("Authenticating to application...")
if err = target.Authenticate(0, *defaultDESFireAESKey); err != nil {
	return err
}

// Change the application transport keys
log.Infof("Changing application transport keys...")
if err = target.ChangeKey(1, *appReadKey, *defaultDESFireAESKey); err != nil {
	return err
}

if err = target.ChangeKey(2, *appAuthKey, *defaultDESFireAESKey); err != nil {
	return err
}

if err = target.ChangeKey(3, *appUpdateKey, *defaultDESFireAESKey); err != nil {
	return err
}

// Create the UUID data file
log.Infof("Writing UUID data file...")
if err = target.CreateDataFile(1, freefare.Enciphered, initialFileSettings, mangledUUIDLength, false); err != nil {
	return err
}

dataLen, err := target.WriteData(1, 0, []byte(mangledUUID))
if err != nil {
	return err
}

if dataLen != mangledUUIDLength {
	return errors.New("failed to write UUID to target")
}

The context surrounding this can be found here (subject to change, active development branch): https://github.com/ComputerScienceHouse/gatekeeper/blob/master/device/nfc.go#L231

This all works and dataLen reports that 32 bytes were written. However, when I go back and read the same file:

appId := freefare.NewDESFireAid(baseAppId + realm.Slot)
appReadKey := keys.GenDESFireKey(realm.ReadKey)

// Select the realm's application
if err := target.SelectApplication(appId); err != nil {
	return nil, err
}

// Authenticate to the application
if err := target.Authenticate(1, *appReadKey); err != nil {
	return nil, err
}

// Read the UUID from the application
mangledUUID := make([]byte, mangledUUIDLength)
dataLen, err := target.ReadData(1, 0, mangledUUID)
if err != nil {
	return nil, err
}

if dataLen != mangledUUIDLength {
	return nil, errors.New("failed to read UUID from target")
}

This runs successfully and dataLen reports that 32 bytes were read, but mangledUUID (the buffer passed to the read function) is all zeros.

I've tried different communication modes (Plain, Enciphered), different data, and attempted to read immediately after writing before any access rights were applied, to no avail. The logic around all of this is based on this project, which uses libfreefare directly: https://github.com/henryk/libopenkey/blob/master/libopenkey/libopenkey.c

Am I doing something incorrectly, or does this have something to do with the read_data buffer overrun bug in libfreefare <= 0.4.0?

Thanks for any insight you may be able to provide!

How to use SelectPassiveTarget with libfreefare?

Hi,

I'm having some issues dealing with libfreefare.
I would like to transform a nfc.ISO14443aTarget into a freefare.Tag to use the SelectPassiveTarget feature of libnfc.

Here is my code:

func Connect(device nfc.Device) (*freefare.DESFireTag, error) {

    // Scan for tags
    modulation := nfc.Modulation{
        Type: nfc.ISO14443a,
        BaudRate: nfc.Nbr424,
    }

    nfcTag, _ := device.InitiatorSelectPassiveTarget(modulation, nil)
    isoTarget, _ := nfcTag.(*nfc.ISO14443aTarget)
    rawTag, _ := freefare.NewTag(device, isoTarget)

    tag := rawTag.(freefare.DESFireTag)

    err = tag.Connect()
    if err != nil {
        return nil, err
    }

    return &tag, nil

}

Am I doing things right here?
The result is a segfault at:

runtime.cgocall(0x454930, 0xc82003fdc8, 0x0)
    /usr/lib/go/src/runtime/cgocall.go:120 +0x11b fp=0xc82003fd70 sp=0xc82003fd40
github.com/fuzxxl/freefare/0.3/freefare._C2func_mifare_desfire_connect(0x7f4e8c006f10, 0x0, 0x0, 0x0)
    ??:0 +0x47 fp=0xc82003fdc8 sp=0xc82003fd70
github.com/fuzxxl/freefare/0.3/freefare.DESFireTag.Connect(0xc8200103a0, 0xffff, 0x0, 0x0)

Thank you for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.